我在我的网站上有一个iframe模态框。我试图点击其中的按钮,但是我无法成功。以下是我的代码,请告诉我我错过了什么。
driver.SwitchTo().Frame(driver.FindElement(By.Id("iframeid='frame_name'")));
driver.FindElement(By.Id("sendReuqest")).Click();
期望结果:点击iframe中的按钮id为sendRequest
实际结果:未找到元素。
如有任何问题,请告知。
我在我的网站上有一个iframe模态框。我试图点击其中的按钮,但是我无法成功。以下是我的代码,请告诉我我错过了什么。
driver.SwitchTo().Frame(driver.FindElement(By.Id("iframeid='frame_name'")));
driver.FindElement(By.Id("sendReuqest")).Click();
期望结果:点击iframe中的按钮id为sendRequest
实际结果:未找到元素。
如有任何问题,请告知。
driver.SwitchTo().Frame(driver.FindElement("iframe_1")));
driver.FindElement(By.Id("sendRequest")).Click();
看起来你正在尝试使用 By.Id()
,但你应该使用 By.CssSelector()
。 By.Id()
期望你传递一个与 HTML 中 ID 元素匹配的参数。
driver.SwitchTo().Frame(driver.FindElement(By.CssSelector("[iframeid='frame_name']")));
driver.FindElement(By.Id("sendReuqest")).Click();
sendRequest
也不像是一个有效的 ID。 - drets试试这个:
driver.SwitchTo().Frame("frame_name");
driver.FindElement(By.Id("sendReuqest")).Click();