使用c#在Selenium中使用SwitchTo()框架

Tek*_*oft 3 html c# selenium frameset frame

我在这个网站上使用了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>
Run Code Online (Sandbox Code Playgroud)

我需要访问以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");
}
Run Code Online (Sandbox Code Playgroud)

是因为Frame(1)不是我想要的帧吗?或者我应该使用不同的方式进入它?

谢谢

Sub*_*ubh 6

此代码也会切换到'src'属性为'/ somesrc'且'id'属性为'unloadFrame'的框架

driver.SwitchTo().Frame(driver.FindElement(By.Xpath("//frame[@src='/somesrc' and not(@id='unloadFrame')]")));
Run Code Online (Sandbox Code Playgroud)