Wednesday, 10 December 2014

How to switch inside a Frame



we have the statement

driver.switchTo().frame();

for switching the driver control inside a frame in AUT.




The frame method is overloaded i.e. 3 varients are available .

We have to use one which best fits the scenario.




1. Using the Xpath/Css Selector

driver.switchTo().frame(iframe_element)

ex:

driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@id='signupsso']")));




2.Using the frame id or name

driver.switchTo().frame(name_or_id)




3.

driver.switchTo().frame(index)

This is the last option to choose, because using index is not stable enough as you could imagine. If this is your only iframe in the page, try driver.switchTo().frame(0)







example:

<iframe frameborder="0" style="border: 0px none; width: 100%; height: 356px; min-width: 0px; min-height: 0px; overflow: auto;" dojoattachpoint="frame" title="Fill Quote" src="https://tssstrpms501.corp.trelleborg.com:12001/teamworks/process.lsw?zWorkflowState=1&zTaskId=4581&zResetContext=true&coachDebugTrace=none">

---------------------above is the DOM-------------------

driver.switchTo().frame(driver.findElement(By.cssSelector("iframe[title='Fill Quote']")

No comments:

Post a Comment