【问题标题】:How can we find the visibility on an element in python selenium?我们如何在 python selenium 中找到元素的可见性?
【发布时间】:2016-05-16 17:30:11
【问题描述】:

我的场景:登录我的帐户后,网页上会打开一个插页式广告。我的用例是,如果显示插页式广告,我会像

一样关闭插页式广告
inter=driver.find_element_by_xpath("/*x-path location/*")

if inter1.is_displayed():
    inter1.click()

但是对于少数用户,插页式广告不会显示,我已经更新了我的代码,如下所示

if(driver.find_element_by_xpath("/*x-path location/*").is_displayed()):
   driver.find_element_by_xpath("/*x-path location/*").close()

else:
   (kept my rest of the class part here)

但我的脚本失败并出现以下错误

有人能帮我提些建议吗,在此先感谢

selenium.common.exceptions.NoSuchElementException:消息:无法定位元素:{"method":"xpath","selector":"/html/body/div[1]/div[2]/div/map /区域[1]"} 堆栈跟踪: 在 FirefoxDriver.prototype.findElementInternal_ (file:///var/folders/7f/q00y41s11xdfknssfymz3qfc0000gv/T/tmp8w0k6J/extensions/fxdriver@googlecode.com/components/driver-component.js:10770) 在 fxdriver.Timer.prototype.setTimeout/<.notify>

【问题讨论】:

    标签: python selenium


    【解决方案1】:

    首先看看:waits methods

    我建议你试试这个解决方案:

    try:
        element = WebDriverWait(driver, 10).until(
            EC.presence_of_element_located((inter1, "myDynamicElement"))
        )
    finally:
        driver.quit()
    

    希望这对你有用。

    【讨论】:

      【解决方案2】:

      找到上述用例的解决方案:

      def is_text_present(driver):
      
      try :
          print "This is is_text_present method"
          body = driver.find_element_by_xpath("Your xpath")
          body.click();
      except NoSuchElementException, e:
          return False
      return True
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-11-16
        • 2021-09-05
        • 2023-03-07
        • 2016-07-18
        • 1970-01-01
        • 1970-01-01
        • 2021-08-15
        • 1970-01-01
        相关资源
        最近更新 更多