PurnenduRath
PurnenduRath

Reputation: 27

Can't click element inside iframe

On the screenhsot below is HTML-code of iframe.

The first two red marked object can be identified by Webdriver however the last marked (which is a button) can't be clicked by Webdriver. I have tried click it using different ways (like click by id, name, etc). But I still can't click the submit button.

Please help me to click that submit button inside the frame. enter image description here

Upvotes: 2

Views: 8566

Answers (2)

Adam Nijiati
Adam Nijiati

Reputation: 1

Same issue happened to me today. It might be simply due to you not switching to the frame, or it could be something I experienced.

This happened to me in IE only. In Chrome there is no problem at all.

Actual Code

As you can see, I did switch to the frame to make sure this element could be found. But, it could not be. The only solution that I found was to put Thread.Sleep(2000) to make it pass. I am not quite sure why, but I guess it has something to do with the content not being available in the DOM.

Upvotes: 0

Richard
Richard

Reputation: 9019

You need to use switchTo().frame() to access content within a frame or iframe.

driver.switchTo().frame("name");  // where name is the name of the iframe i.e. name="frameName", you would use framename
driver.switchTo().frame(0);       // You can switch to the frame by index
driver.switchTo().frame(element); // You can switch to the frame by a WebElement reference

In your particular case you can use:

driver.switchTo().frame("InstantSgn");

To switch out of the frame after you're done within the iframe context:

driver.switchTo().defaultContent();

Upvotes: 5

Related Questions