Python硒1

Python Selenium1

嘿,我是 python selenium 开发的新手,如果有人有多余的时间,我有点需要帮助:)

我正在使用这个网站:https://www.youlikehits.com/retweets.php 我正在尝试点击绿色的确认按钮。但是对于某些共鸣,我无法弄清楚如何单击它。每次尝试都说找不到。

你们有ide吗?

屏幕: https://i.stack.imgur.com/Z31In.png html 代码的屏幕: https://i.stack.imgur.com/herDB.png

代码:

driver.find_element_by_link_text('Confirm').click()


try:
        print("Trying")
        print("Making points Click")
        time.sleep(5)
except NoSuchAttributeException:
        print("Element not found!")
        continue
except:
        print("Something els is wrong!")

driver.quit()

最好的问候菲利克斯

Confirm link 在 iframe 中,您需要先切换到 iframe 才能访问该元素。

使用 WebDriverWait() 等待 frame_to_be_available_and_switch_to_it() 并跟随 css 选择器 使用 WebDriverWait() 等待 element_to_be_clickable() 并跟随 xpath

driver.get("url")
wait=WebDriverWait(driver,10)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe[src^='retweetrender.php']")))
wait.until(EC.element_to_be_clickable((By.XPATH,"//a[contains(.,'Confirm')]"))).click()

driver.get("url")
wait=WebDriverWait(driver,10)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe[src^='retweetrender.php']")))
wait.until(EC.element_to_be_clickable((By.LINK_TEXT,"Confirm"))).click()

您需要以下导入。

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By