【问题标题】:Worked on 2 hours but cannot clicked on the button with Selenium [duplicate]工作了 2 小时,但无法单击 Selenium 的按钮 [重复]
【发布时间】:2019-10-22 00:45:13
【问题描述】:

我想点击这个按钮,但我的代码不起作用。

我尝试的最后一个是:driver.find_element_by_xpath("/html/body/app/main/app/div/div/e-arsiv/taslaklar/div[2]/div/div/div[2]/uc-quick-filter[@type='3M]").click()

我得到这个错误:

elenium.common.exceptions.InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression /html/body/app/main/app/div/div/e-arsiv/taslaklar/div[2]/div/div/div[2]/uc-quick-filter[@type='3M] because of the following error:
SyntaxError: Failed to execute 'evaluate' on 'Document': The string '/html/body/app/main/app/div/div/e-arsiv/taslaklar/div[2]/div/div/div[2]/uc-quick-filter[@type='3M]' is not a valid XPath expression.

这里是html

【问题讨论】:

    标签: python python-3.x selenium xpath selenium-chromedriver


    【解决方案1】:

    您的text 缺少单引号。

    driver.find_element_by_xpath("/html/body/app/main/app/div/div/e-arsiv/taslaklar/div[2]/div/div/div[2]/uc-quick-filter[@type='3M']").click()
    

    【讨论】:

    • 不幸的是,它给出了以下错误。我还尝试使用隐式等待: selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element ... 在点 (319, 147) 是不可点击的。其他元素会收到点击:
      ...
    • 试试这个driver.find_element_by_xpath("/html/body/app/main/app/div/div/e-arsiv/taslaklar/div[2]/div/div/div[2]/uc-quick-filter[@type='3M'][1]").click()
    • same error :(
      ...
      显然阻止我们点击按钮。但是,我没有在屏幕上看不到任何阻挡的东西。
    • execute_script 方法解决了问题
    【解决方案2】:

    绝对 xpath 不太可取。像这样使用 css


    driver.find_element_by_css_selector ("uc-quick-filter.ng-untouched.ng-invalid[type='3M']").click()
    

    【讨论】:

    • 这也没有用:( throwing --> selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","选择器":"uc-quick-filter.ng-untouched.ng-invalid[type='3M']"}
    【解决方案3】:

    尝试使用chrome再次复制xpath--> F12 -->右键单击元素-->复制-->xpath

    【讨论】:

      猜你喜欢
      • 2020-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多