Python 已工作2小时,但无法使用Selenium单击按钮
我想点击这个按钮,但我的代码不起作用 我最后尝试的是:Python 已工作2小时,但无法使用Selenium单击按钮,python,python-3.x,selenium,xpath,selenium-chromedriver,Python,Python 3.x,Selenium,Xpath,Selenium Chromedriver,我想点击这个按钮,但我的代码不起作用 我最后尝试的是:driver.find\u element\u by_xpath(“/html/body/app/main/app/div/div/e-arsiv/taslaklar/div[2]/div/div/div/2]/uc quick filter[@type='3M]”。单击() 我得到了这个错误: elenium.common.exceptions.InvalidSelectorException: Message: invalid selec
driver.find\u element\u by_xpath(“/html/body/app/main/app/div/div/e-arsiv/taslaklar/div[2]/div/div/div/2]/uc quick filter[@type='3M]”。单击()
我得到了这个错误:
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.
这是您的文本中缺少的单引号
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()
绝对xpath不太可取。像这样使用css
尝试使用chrome-->F12-->右键单击元素-->copy-->xpath再次复制xpath这也不起作用:(抛出-->selenium.common.exceptions.NoTouchElementException:Message:没有这样的元素:找不到元素:{“方法”:“css选择器”,“选择器”:“uc quick filter.ng untouched.ng无效[type='3M']”不幸的是,它给出了下面的错误。我还尝试使用隐式等待:selenium.common.exceptions.ElementClickInterceptedException:Message:element click intercepted:element…在点(319147)处不可单击。其他元素将收到单击:…try thisdriver.find_element_by_xpath(“/html/body/app/main/app/div/div/e-arsiv/taslaklar/div[2]/div/div/div/div/2]/uc quick filter[@type='3M'][1]”。单击()
相同的错误:(…显然阻止了我们单击按钮。但是,我在屏幕上没有看到任何东西阻止。执行脚本方法解决了这个问题。”
driver.find_element_by_css_selector ("uc-quick-filter.ng-untouched.ng-invalid[type='3M']").click()