【发布时间】:2022-01-16 10:45:30
【问题描述】:
我试图在 selenium 中为网站创建一个 for 循环,以检查几个按钮之一是否可单击,然后单击它,如果在可单击之前不刷新它。现在使用我的 Xpath,我在以下代码下方收到错误(InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression Xpath=...
如果你能帮上忙就好了 我还没有找到任何对我有帮助的东西! 否则,我的问题的不同解决方案也会很好! 谢谢!
paths = ['Xpath=//*[@id="mms-app-root"]/div[2]/div/div[2]/div[2]/div[2]/div/div/div/div/div[4]/div[1]/div[2]/button', 'Xpath=//*[@id="mms-app-root"]/div[2]/div/div[2]/div[2]/div[3]/div/div/div/div/div[4]/div[1]/div[2]/button', 'Xpath=//*[@id="mms-app-root"]/div[2]/div/div[2]/div[2]/div[4]/div/div/div/div/div[4]/div[1]/div[2]/button']
for i in range(len(paths)):
if(len(wd.find_elements_by_xpath(paths[i])) > 0):
wd.find_element_by_xpath(paths[i]).click()
break
else:
print('not available')
time.sleep(8)
wd.refresh()
time.sleep(2)
InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression Xpath=//*[@id="mms-app-root"]/div[2]/div/div[2]/div[2]/div[2]/div/div/div/div/div[4]/div[1]/div[2]/button because of the following error:
TypeError: Failed to execute 'evaluate' on 'Document': The result is not a node set, and therefore cannot be converted to the desired type.
【问题讨论】: