search

Home  >  Q&A  >  body text

python - seleuimn中find_element_by_xpath找不到元素

代码如图

wait = WebDriverWait(self.browser,20)
wait.until(EC.element_to_be_clickable((By.ID,'city')))
self.browser.find_element_by_xpath('//*[@id="city"]/li[2]').click()

log报的错误是找不到元素city,我查看了self.browser的sourcepage属性,是有id属性为city的元素的.

高洛峰高洛峰2804 days ago880

reply all(3)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 17:26:32

    Try to locate by id or text in other ways

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 17:26:32

    Write a more specific xpath, for example: "/img[@src='images/sidebar/icon-nav-white-community.879b43c0.svg']"

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 17:26:32

    waitUntil occasionally has bugs, it is recommended to use js to trigger it

    reply
    0
  • Cancelreply