我在这个网站上使用了selenium,但我不能使用它的任何元素。因为它们来自'frame'而且来自'frameset',这里是html部分;
<frameset rows="0%, 95%" frameborder="0" frameSpacing="0" marginHeight="0" marginWidth="0">
<frame id='unloadFrame' src="/somesrc" noresize>
<frame src="/somesrc" noresize>
</frameset>
<noframes>
Your browser doesn't support frames, This web site requires a frames capable browser.
</noframes>
我需要访问以src开头的第二帧,我使用了这个方法,但仍然无法使用任何元素;
driver.SwitchTo().Frame(1);
Boolean sa = driver.FindElements(By.Id("ctl00_MainContent_txtCustomerId")).Count > 0;
if (sa == true)
{
driver.FindElement(By.Id("ctl00_MainContent_txtCustomerId")).SendKeys("HelloWorld");
}
是因为Frame(1)不是我想要的帧吗?或者我应该使用不同的方式进入它?
谢谢
此代码也会切换到'src'属性为'/ somesrc'且'id'属性为'unloadFrame'的框架
driver.SwitchTo().Frame(driver.FindElement(By.Xpath("//frame[@src='/somesrc' and not(@id='unloadFrame')]")));
我正在编写这种简单的方法来在Iframe中输入文本。
public void SwitchToIframeandEnterText(IWebElement frame,
IWebElement field, string txt)
{
Driver.SwitchTo().Frame(frame);
field.SendKeys(txt);
Driver.SwitchTo().DefaultContent();
}
哪里,
- IWebElement frame = Iframe的定位器
- IWebElement field =您要输入文本的Field的定位器
- string txt =您要输入的文本
在C#中切换IFrame -
例如-