在python中使用seleniumxpath

2024-06-08 02:01:38 发布

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

我尝试使用XPATH点击两个不同的部分。它适用于第一个链接,但会抛出一条错误消息

ElementReferenceException:消息:在缓存中找不到u'Element-可能该页在查找后已更改

    driver.find_element_by_id("twotabsearchtextbox").send_keys("watches")
    driver.find_element_by_css_selector("input.nav-submit-input").click()
    driver.find_element_by_css_selector("ul.refinementNodeChildren > li > a >span.childRefinementLink").click()
    driver.find_element_by_xpath("//ul[@id='ref_199497031']/li[4]/a/span[text()='Chronograph']").click()
    driver.find_element_by_xpath("//ul[@id='ref_199493031']/li[2]/a/span[text()=\"Men's\"]").click()

在上面的代码中

程序发现XPATH的第一个元素“Chronograph”可以正常工作,但是第二个元素“Men's”就不行了。。在

如果我交换最后两行。。在

^{pr2}$

在本例中,XPATH“Men's”的第一个元素工作正常,但第二个元素“Chronograph”不起作用

我不确定它是否退出先前的xpath来找到新的xpath!!有没有办法退出XPATH以便在页面中找到其他元素?在


Tags: id消息元素bydriverlielementfind

热门问题