4

I have a iframe modal under my site. I am trying to click button in it but I am unable to do so. Below is my code. Please let me know what am i missing

driver.SwitchTo().Frame(driver.FindElement(By.Id("iframeid='frame_name'"))); 
driver.FindElement(By.Id("sendReuqest")).Click();

Expected Result: Button id: sendRequest should get clicked which is on iframe

Actual Result: Element is not found.

Please let me know if you have any questions.

8
  • Please next time considering to ask unrelated questions separately. Commented Dec 22, 2015 at 19:53
  • Where is unrelated question here? Commented Dec 22, 2015 at 20:01
  • I mean 2 different questions: 1) click button inside frame 2) check total time to load a grid, does it answer your question? Thanks! Commented Dec 22, 2015 at 20:02
  • 1
    Both are related to one thing which is Selenium Automation which I added as title of my question as well. I will remove one question. And will ask that in my seperate post. Thanks!! Commented Dec 22, 2015 at 20:19
  • Coolawesome, also please explain unable to do so. Do you have any exceptions? If yes, please include it in the question. Commented Dec 22, 2015 at 20:21

3 Answers 3

1

Try to do it this way. Let's take frame_name id as iframe_1. Whatever you frame id is you can add instead of iframe_1. Also you have a spelling mistake (typo) it might be sendRequest so I am adding as id of your button.

driver.SwitchTo().Frame(driver.FindElement("iframe_1"))); 
driver.FindElement(By.Id("sendRequest")).Click();

Hope it works. Please do comment and let us know.

Best of luck.

Sign up to request clarification or add additional context in comments.

2 Comments

Yes, now I am able to click that button but I am facing another problem. Steps is to open that frame,click on button, frame closes,then it clicks on another button. When button is clicked on that frame and then frame gets closed but now not able to click on next button
I am receving this error: Element not found in the cache - perhaps the page has changed since it was looked up
0

It looks like you're trying to use By.Id() when you should be using By.CssSelector(). By.Id() expects you to pass a parameter which matches the ID element in the HTML.

driver.SwitchTo().Frame(driver.FindElement(By.CssSelector("[iframeid='frame_name']"))); 
driver.FindElement(By.Id("sendReuqest")).Click();

1 Comment

sendReuqest also doesn't look like a valid id.
0

Try that one:

driver.SwitchTo().Frame("frame_name"); 
driver.FindElement(By.Id("sendReuqest")).Click();

1 Comment

Thanks Leon. But Answer posted by user3542501 worked so I am going to use that. Appreciate your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.