Jen Jen - 20 days ago 6
Ruby Question

Seleium/Ruby - NoSuchElement when trying to access an item in a modal popup

What I'm attempting:


  1. Click on a the profile picture of a user that I previously created: http://screencast.com/t/AJCFI3XA

  2. Click on and make a selection from a drop down in the pop up modal:
    http://screencast.com/t/AHGOHlG05



The
selenium IDE
picks up the steps as:


  1. click >
    id=patientPhoto

  2. selectWindow >
    name=modal3
    (NOTE that the modal number changes and increases exponentially, if i run these steps again the next time around it's modal4)

  3. click >
    id=ext-gen115
    click >
    //div[@id='ext-gen179']/div[2]



This playback in the ide works without issue.

My code:

@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


In other places/workflows I have to do the switch to default content then switch to frame trick:

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


but no combination of that is working here.

Other things I've tried:

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


Here's the page coding - http://screencast.com/t/OSIIgjxDbLk

The
selenium
errors I get vary based on what I'm attempting but it's either timeout or cannot find element.

Answer

If there is an iframe with dynamic id, try to use following line of code to switch to it:

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