首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Selenium python中切换到iframe后找不到元素

在Selenium python中切换到iframe后找不到元素
EN

Stack Overflow用户
提问于 2019-12-24 14:23:53
回答 1查看 73关注 0票数 0

我正在运行一个测试用例,其中一部分是检查iframe中的元素是否可见。我执行了以下操作,但它不起作用,总是转到except块。谢谢

代码语言:javascript
复制
try:
    time.sleep(2)
    driver.switch_to.frame("iframe-xxxxxxxxxxxxxxxxxx")
    time.sleep(2)
    if driver.find_element_by_xpath("//div[@class='col-11 answer-feedback-label']//div[contains(text(),'Hello World!')]"):
        logging.info("Success")
except:
     logging.error("Failure")
EN

回答 1

Stack Overflow用户

发布于 2019-12-24 15:27:28

要检查<iframe>中的元素是否可见,就像<iframe>中的所需元素一样,因此您必须:

适用于visibility_of_element_located().

  • You的所需frame_to_be_available_and_switch_to_it().

  • Induce WebDriverWait的
  • Induce可以使用以下解决方案:

代码语言:javascript
复制
- Code Block:

从selenium导入webdriver从selenium.webdriver.support.ui导入WebDriverWait从selenium.webdriver.support导入expected_conditions作为EC从selenium.webdriver.common.by导入通过导入org.openqa.selenium.TimeoutException;。。。try: driver(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,“iframe_XPATH”)) WebDriverWait(driver,div "//div@class='col-11 answer-feedback-label‘//WebDriverWait(text(),'Hello World!’)“)除TimeoutEception以外的logging.info(“成功”):logging.error(“失败”)

在这里,您可以在Ways to deal with #document under iframe

上找到相关讨论

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59464661

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档