C# Selenium: Click button under iframe

我的未来我决定 提交于 2019-12-12 14:34:23

问题


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.


回答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.




回答2:


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();



回答3:


Try that one:

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


来源:https://stackoverflow.com/questions/34422364/c-sharp-selenium-click-button-under-iframe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!