Seleium / Ruby - 尝试访问模态弹出窗口中的项目时的NoSuchElement

时间:2016-11-17 15:22:12

标签: ruby selenium selenium-webdriver webdriver

我在尝试:

  1. 点击我之前创建的用户的个人资料照片:http://screencast.com/t/AJCFI3XA

  2. 点击并从弹出式模式的下拉列表中进行选择: http://screencast.com/t/AHGOHlG05

  3. selenium IDE选择以下步骤:

    1. 点击> id=patientPhoto
    2. selectWindow> name=modal3注意,如果我下次再次执行这些步骤' s modal4,则模态编号会以指数方式更改并逐渐增加)
    3. 点击> id=ext-gen115点击> //div[@id='ext-gen179']/div[2]
    4. ide中的这种播放没有问题。

      我的代码:

      @driver.find_element(:id, "patientPhoto").click
      wait_for { displayed?(:id, "ext-gen31") }
      @driver.find_element(:id, "ext-gen31").click
      @driver.find_element(:xpath, "//div[@id='ext-gen179']/div[2]").click
      

      在其他地方/工作流程中,我必须切换到默认内容,然后切换到帧技巧:

      @driver.switch_to.default_content
      @driver.switch_to.frame('chartFrame') 
      

      但没有任何组合在这里工作。

      我尝试过的其他事情:

      1.  Switch to the last window like this:  @driver.switch_to.window(@driver.window_handles.last) # this doesn't fail but the step after this (finding the drop down) fails
      2.  @driver.switch_to.frame('modal4') then attempt to access the items in the modal  # this fails i think because the modal number keeps changing 
      

      这是页面编码 - http://screencast.com/t/OSIIgjxDbLk

      我得到的selenium错误因我尝试的内容而异,但是超时或无法找到元素。

1 个答案:

答案 0 :(得分:1)

如果iframe有动态id,请尝试使用以下代码行切换到它:

@driver.switch_to.frame(@driver.find_element(:xpath, "//iframe[contains(@id, 'modal')]"))