无法找到框架?红宝石

时间:2019-06-06 20:27:30

标签: ruby selenium-webdriver

我是Ruby和Selenium的新手,我以为我已经改用框架来定位包中的某个元素,但看起来好像不是。

运行脚本时,出现以下错误:

Selenium::WebDriver::Error::NoSuchFrameError: Unable to locate frame: 1

or

Selenium::WebDriver::Error::StaleElementReferenceError

但是html中存在一个iframe,该iframe围绕着我要查找的元素。我使用Selenium记录器更好地弄清楚了这是哪一帧,它告诉我索引是1。我尝试通过其ID定位该帧,但无法找到它。然后,我尝试等待20-60秒,以期以某种方式起作用。只是超时。

在其他时间切换帧和现在之间,我可以看到的唯一区别是我现在正在寻找的帧在一个循环内。会影响吗?任何帮助表示赞赏!

这是我的代码:


select_list.options.each { |option|
             if option.text == ""
                @driver.find_element(xpath: '//*[@id="txt_source"]/option[2]').click

                @driver.find_element(xpath: '//*[@id="search_button"]/button[2]').click #small arrow

                sleep(10)

                @driver.find_element(xpath: '//*[@id="search_button"]/div/a[3]').click #Button that navigates to the next page


                sleep(10)
                @driver.find_element(xpath: '//*[@id="main_action"]').click




                @driver.switch_to.frame(1) #Where is fails




                @driver.find_element(xpath: '/html/body/table/tbody/tr[2]/td/table/tbody/tr[2]/td/input').click

               @driver.switch_to.default_content


             end

        }

1 个答案:

答案 0 :(得分:0)

如果作为循环的一部分切换到框架,则需要切换回该框架,否则循环的第二次迭代将无法进行。

eq_refl
相关问题