0% found this document useful (0 votes)
4 views2 pages

XPath

Uploaded by

tekkafaliwither
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

XPath

Uploaded by

tekkafaliwither
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

from selenium import webdriver

from [Link] import By


from [Link] import WebDriverWait
from [Link] import expected_conditions as EC
import time

# Web sürücüsünü başlat


driver = [Link]()

# Hedef URL'yi aç
[Link]('[Link]

# Sayfanın yüklenmesi için bekle


[Link](2)

# Beklenen değerler
expected_image_src =
'[Link]
[Link]'
expected_text = 'Nobu'

# Butonlara tıklanıp tıklanmadığını kontrol et


open_button_clicked = False
avatar_clicked = False

def update_elements():
global open_button_clicked, avatar_clicked
try:
# PC PRE-REGISTER butonunu bul ve tıkla
if not open_button_clicked:
open_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable(([Link],
'//*[@id="app-chat"]/div[1]/ul/li[2]'))
)
open_button.click()
open_button_clicked = True # Butona tıklandığını kaydet

# Onay kutusunu bul ve tıkla


if not avatar_clicked:
avatar = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable(([Link],
'//*[@id="app-chat"]/div[1]/ul/li[2]/div[2]/div[5]/div/div[2]'))
)
[Link]()
avatar_clicked = True # Butona tıklandığını kaydet

# Resmin XPath'ini bul


image_element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located(([Link],
'//*[@id="avatarWrap"]/div[2]/img'))
)

# Yazının XPath'ini bul


text_element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located(([Link],
'//*[@id="app-chat"]/div[1]/div/div/div[2]'))
)

# Kontrol et ve güncelle
current_image_src = image_element.get_attribute("src")
current_text = text_element.get_attribute("innerText")

# Resmi güncelle
if current_image_src != expected_image_src:
driver.execute_script("arguments[0].src = arguments[1];",
image_element, expected_image_src)
print("Görsel geri yüklendi.")

# Yazıyı güncelle
if current_text != expected_text:
driver.execute_script("arguments[0].innerText = arguments[1];",
text_element, expected_text)
print("Yazı geri yüklendi.")

except Exception as e:
print(f"Güncelleme hatası: {e}")

# İlk güncellemeyi yap


update_elements()

# Tarayıcı açık kalacak, kapatmak için manuel olarak kapatabilirsiniz


print("Tarayıcı açık. Kapatmak için Ctrl + C tuşlarına basın.")

# Sürekli kontrol döngüsü


try:
while True:
[Link](2) # 2 saniye bekle, ardından kontrol et
update_elements()

except KeyboardInterrupt:
print("Tarayıcı kapatılıyor...")

You might also like