已工作2小时,但无法使用Selenium单击按钮

2024-06-26 10:14:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我想按一下这个按钮,但我的代码不工作。你知道吗

我最后尝试的是: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


Tags: thetodivappmainhtmltypebody
3条回答

您的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()

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


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

使用chrome>;F12>;右键单击element>;copy>;xpath再次尝试复制xpath

相关问题 更多 >