Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 单击Tinder登录按钮时没有此类元素错误_Python_Selenium - Fatal编程技术网

Python 单击Tinder登录按钮时没有此类元素错误

Python 单击Tinder登录按钮时没有此类元素错误,python,selenium,Python,Selenium,我试图学习如何使用python与internet交互,并遵循了我找到的关于如何制作与tinder交互的机器人的教程。我可以打开一个chrome窗口,它可以进入网站,但当我尝试单击登录按钮时遇到问题。下面是我使用的代码(我从selenium导入了webdriver,并不时地休眠,但它不会在这里传输): 使用此代码后得到的错误代码是: selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable

我试图学习如何使用python与internet交互,并遵循了我找到的关于如何制作与tinder交互的机器人的教程。我可以打开一个chrome窗口,它可以进入网站,但当我尝试单击登录按钮时遇到问题。下面是我使用的代码(我从selenium导入了webdriver,并不时地休眠,但它不会在这里传输):

使用此代码后得到的错误代码是:

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
    
  • 浏览器快照:


参考文献 您可以在以下内容中找到详细的相关讨论:


确保这是正确的xpath,首先在浏览器中测试它。如果是,则很可能元素仍然未加载或已消失。在这种情况下,您可能需要等待它以隐式等待方式出现。在Selenium中搜索暂停的元素和隐式等待。
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC