Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/279.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
无法使用selenium在Python中定位元素_Python_Selenium_Xpath_Css Selectors_Webdriverwait - Fatal编程技术网

无法使用selenium在Python中定位元素

无法使用selenium在Python中定位元素,python,selenium,xpath,css-selectors,webdriverwait,Python,Selenium,Xpath,Css Selectors,Webdriverwait,我在使用xPath定位元素时遇到问题 嘿,我试过使用xPath和其他方法,但找不到该元素。如果您试图单击下拉按钮,请使用下面的xPath //li/a[@href="/drop"]//span[.='Drop'] 包括以下进口: from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC from selenium.webdriv

我在使用xPath定位元素时遇到问题


  • 嘿,我试过使用xPath和其他方法,但找不到该元素。

    如果您试图单击下拉按钮,请使用下面的xPath

    //li/a[@href="/drop"]//span[.='Drop']
    

    包括以下进口:

    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.support.ui import WebDriverWait
    
    您的代码应该是:

    WebDriverWait(driver,30).until(EC.element_to_be_clickable((By.XPATH, "//li/a[@href='/drop']//span[.='Drop']"))).click()
    
    要在元素上单击(),您必须引导WebDriverWait使
    元素成为可单击的()
    ,并且您可以使用以下任一选项:

    • 使用
      CSS\u选择器

      WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "li > a[href=/drop] > button span:nth-of-type(2)")))
      
    • 使用
      XPATH

      WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//li/a[@href='/drop']/button//span[text()='Drop']")))
      
    • 注意:您必须添加以下导入:

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

    您尝试单击哪个跨度?是Drop还是pin_Drop?如果可能的话,提供可能有帮助的链接。上述代码将确保脚本将等待Drop元素可单击。您是否尝试过我的答案中的代码?如果仍然出现NoTouchElement异常,则可能必须检查元素是否存在于iframe中。名称错误:未定义名称“驱动程序”仍然无法正常工作是的,我包含了所有内容仍然无法正常工作我完成了它仍然无法正常工作名称错误:未定义名称“驱动程序”不在iframe@LukasAlišauskas查看更新的回答并让我知道状态。
    raise-TimeoutException(message,screen,stacktrace)selenium.common.exceptions.TimeoutException:message:
    使用xPath时仍然出现错误@DebanjanB它没有显示错误,但没有显示错误working@LukasAlišauskas TimeoutException是预期条件失败的结果。通过
    find\u element\u by.*
    time.sleep()
    一起调试代码。如果您能够找到元素,请使用观察结果更新问题。检查HTML并向上遍历,观察元素是否在标记内,然后在单击元素之前必须先切换到所需的
    。检查此项尝试了很多东西,但仍然没有写入阅读全文讨论仍然我遇到错误当我试图通过控制台查找元素时没有错误i
    获取未捕获的语法错误:意外标识符
    ,但当我使用ChroPath时,它会查找元素和所有内容ok请帮助@supputuri找到方法
    驱动程序。获取('https://link/drop')
    像这样,但有一个按钮,我不能点击它,同样的问题
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC