How to switch to the correct iframe when iframes do not have id or name?

When iframes do not have name,ids its very hard to identify them or switch to correct iframes.

Below is an example where we can understand the scenario in better way.

Below  is an example where iframes do not have name,ids but you can easily notice that  both the iframes have  src with them.

we can use src to uniquely  identify and switch to the correct iframe.

To identify the correct iframe with src we can use below technique.

 

  driver.switchTo().frame(driver.findElement(By.xpath("//iframe[contains(@src,'Enter here the unique text which belongs to your iframe')]")));  
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s