用于框架的python selenium "Explicit Waits"

标签 python selenium

在同一个页面同一个步骤,如果使用“wait”会得到错误信息 “NoSuchElementException:消息:无法找到名称 == rw 的元素”

如果使用“switch_to_frame”将成功切换框架..

为什么会有不同?

1)

wait = WebDriverWait(driver, 300)
wait.until(EC.frame_to_be_available_and_switch_to_it(driver.find_element_by_name('rw')))

2)

driver.switch_to_frame('rw')

3)

class cm(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Ie()
        self.driver.implicitly_wait(30)
        self.base_url = "http://mytestweb.com"


    def testcm(self):
        driver = self.driver
        driver.maximize_window()
        self.driver.get(self.base_url)
        wait = WebDriverWait(driver, 30)
        self.main_wh = driver.window_handles
##        wait.until(EC.invisibility_of_element_located((By.ID,'Frame2')))
        wait.until(EC.frame_to_be_available_and_switch_to_it((By.NAME,'rw')))
##        driver.switch_to_frame('rw')

如果我尝试使用 3) 将收到超时消息

最佳答案

最有可能的是名称为 rw 的元素,它实际上需要时间来加载,但在查找发生之前没有正确加载。基本上,您是在预期条件出现之前寻找相同的元素。更好的实现如下:

wait = WebDriverWait(driver, 300)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.NAME,'rw')))

参见 doc

关于用于框架的python selenium "Explicit Waits",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30148189/

相关文章:

ajax - Selenium:如何在 AJAX 之后等待 AngularJS 完成 DOM 更新?

javascript - 无法在 Protractor 中运行三个文件?

ant - 运行easyb\selenium时出现permgen错误

python - 根据条件在任意嵌套列表中查找组合

python - 为什么 Tensorflow Reshape tf.reshape() 会破坏梯度流?

python - 像 pubsubhubbub 这样不依赖于谷歌应用引擎的东西

python - 在 python 中将文本添加到循环

python - setuptools find_packages 返回空列表

selenium - 无法在 45000 毫秒内绑定(bind)到锁定端口 7054

django - 502 Bad Gateway with DigitalOcean (gunicorn/nginx) 使用 Selenium 和 Django