Python 单击Tinder登录按钮时没有此类元素错误
我试图学习如何使用python与internet交互,并遵循了我找到的关于如何制作与tinder交互的机器人的教程。我可以打开一个chrome窗口,它可以进入网站,但当我尝试单击登录按钮时遇到问题。下面是我使用的代码(我从selenium导入了webdriver,并不时地休眠,但它不会在这里传输): 使用此代码后得到的错误代码是:Python 单击Tinder登录按钮时没有此类元素错误,python,selenium,Python,Selenium,我试图学习如何使用python与internet交互,并遵循了我找到的关于如何制作与tinder交互的机器人的教程。我可以打开一个chrome窗口,它可以进入网站,但当我尝试单击登录按钮时遇到问题。下面是我使用的代码(我从selenium导入了webdriver,并不时地休眠,但它不会在这里传输): 使用此代码后得到的错误代码是: selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="modal-manager"]/div/div/div/div/div[3]/div[2]/button"}
如能帮助解决此问题,我们将不胜感激。谢谢 根据您的代码测试定位器:
//*[@id="modal-manager"]/div/div/div/div/div[3]/div[2]/button
表示按钮,文本为登录Facebook,要在元素上调用单击()
,您需要引导WebDriverWait使元素可单击()
到达子元素,并且您可以使用以下任一项:
- 使用
:CSS\u选择器
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[type = 'button'][aria-label = 'Log in with Facebook'] span"))).click()
- 使用
:XPATH
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//button[@type = 'button' and @aria-label = 'Log in with Facebook']//span"))).click()
- 注意:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
- 浏览器快照:
参考文献 您可以在以下内容中找到详细的相关讨论:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC