Access frame via “relative=up” with Selenium & Rub

2019-09-16 03:27发布

问题:

Recently I've used command "selectFrame > relative=up" in Selenium IDE to switch between nested frames. Since i've decided to rewrite all code in Selenium and Ruby, i can't find this command analog for mentioned language.

I can't select frame by name because it different after any reload. Other frame attributes are:

iframe id="ext-comp-1465" name="ext-comp-1465" frameborder="0" src="/5005700001V96Ub/e?retURL=%2F5005700001V96Ub&amp;isdtp=vw&amp;cancelURL=%2F5005700001V96Ub&amp;nonce=a37ade0829c6d08539a765cd370dff0766cd596851439e853d68a60e9d7c28d0&amp;sfdcIFrameOrigin=https%3A%2F%2F*************.com" class=" x-border-panel" style="left: 0px; top: 0px; width: 329px; height: 641px;"></iframe

Please advise how i can get to this frame using "relative=up" option or other frame attributes. Thanks in advance.

回答1:

Try the following,

driver.switch_to.frame "ext-comp-1465"

or

driver.switch_to.frame driver.find_element(id: 'ext-comp-1465')

or

driver.switch_to.frame driver.find_element(name: 'ext-comp-1465')

or

driver.switch_to.frame driver.find_element(xpath: '//iframe[starts-with(@id,"ext-comp-"] ')


回答2:

Final solution:

frames = @driver.find_elements(:xpath, '//iframe[starts-with(@id,ext-comp-)]')
@driver.switch_to.frame frames[1]