我想使用selenium登录网站https://www.winamax.es/account/login.php?redir=/apuestas-deportivas。情况是,我找不到xpath/id/text以使te下一个代码成功运行:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
options = webdriver.ChromeOptions()
options.add_argument("window-size=1920,1080")
options.add_argument('--disable-blink-features=AutomationControlled')
driver=webdriver.Chrome(options=options,executable_path=r"chromedriver.exe")
driver.get("https://www.winamax.es/account/login.php?redir=/apuestas-deportivas")
WebDriverWait(driver=driver, timeout=15).until(
lambda x: x.execute_script("return document.readyState === 'complete'")
)
upload_field = driver.find_element_by_xpath("//input[@type='email']")
对于这个示例,我不仅需要特定的xpath,而且我更喜欢使用一种方法来获取xpath或类似的东西,以使代码适用于网站的其他部分
元素位于iframe中。切换到它
进口
完整的工作代码
email元素位于
<iframe>
内,因此您必须:诱导WebDriverWait使所需的帧可用,并切换到它
诱导WebDriverWait使所需的元素可单击
您可以使用以下任一Locator Strategies:
使用
CSS_SELECTOR
:使用
XPATH
:注意:您必须添加以下导入:
浏览器快照:
参考文献
您可以在以下内容中找到一些相关讨论:
相关问题 更多 >
编程相关推荐