python-3.x - 使用 Selenium ,如何单击下拉菜单进入https://www.phptravels.net/的登录页面

标签 python-3.x selenium xpath css-selectors webdriverwait

我有以下要自动化的网站:
https://www.phptravels.net/

我想单击“我的帐户”以到达“注册”和“登录”。

目前,我正在通过导航手动进行操作:

https://www.phptravels.net/demo/login

https://www.phptravels.net/demo/register

我正在为此使用python 3.7

我试过使用Xpath找到它,但是没有运气。它找不到项目,也无法单击它们。

[![<a href="javascript:void(0);" data-toggle="dropdown" class="dropdown-toggle go-text-right"><i class="icon_set_1_icon-70 go-right"></i> My Account <b class="lightcaret mt-2 go-left"></b></a>][1]][1]


请参阅附件图片

最佳答案

要通过url https://www.costcobusinessdelivery.com/LogonForm?URL=%2f登录到Costco.com,因为所需元素位于<iframe>中,因此您必须:


促使WebDriverWait提供所需的帧并切换到该帧。
诱导WebDriverWait使所需的元素可单击。
您可以使用以下解决方案:


css_selector

driver.get("https://www.phptravels.net/")
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe.full-screen-preview__frame")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "nav li#li_myaccount>a"))).click()

xpath

driver.get("https://www.phptravels.net/")
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@class='full-screen-preview__frame']")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//nav//li[@id='li_myaccount']/a"))).click()


浏览器快照:


phptravels_login_menu

关于python-3.x - 使用 Selenium ,如何单击下拉菜单进入https://www.phptravels.net/的登录页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58032540/

相关文章:

python-3.x - 我在 MNIST 上的逻辑回归中没有获得所需的准确度

python - 在网站上查找一个单词并获取其页面链接

python - 值错误 : day is out of range for month datetime

angularjs - 无法让 Protractor 等待现有元素可点击(condition.elementToBeClickable)

java - 为 Selenium 页面对象模型框架编写通用方法

java - XPath:提取多个子节点值

python - 如何在 Python3 中添加带有标志的命令行参数?

post - 是否可以在 Selenium 中捕获 POST 数据?

xml - 如何返回同一级别的子类别?

python - ElementNotInteractableException : Message: element not interactable error sending text in search field using Selenium Python