0
我試圖遵循一些方法來訪問iframe像selectFrame(「index = 1」)方法和 selectFrame(「// iframe [@src ='網址路徑']「)。但是,以上都沒有讓我訪問iframe。如何選擇iframe使用硒2如果iframe只有屬性src和樣式
我的樣品iframe中看起來像這樣<iframe src = "" style = ""></iframe>
我試圖遵循一些方法來訪問iframe像selectFrame(「index = 1」)方法和 selectFrame(「// iframe [@src ='網址路徑']「)。但是,以上都沒有讓我訪問iframe。如何選擇iframe使用硒2如果iframe只有屬性src和樣式
我的樣品iframe中看起來像這樣<iframe src = "" style = ""></iframe>
您可以使用像這樣的SWITCHTO()函數:
[TestMethod]
public void iframeTest()
{
driver = new InternetExplorerDriver();
driver.Navigate().GoToUrl("http://localhost:2720/Default.aspx");
driver.SwitchTo().Frame(0);
IWebElement query = driver.FindElement(By.Id("txtTest"));
query.SendKeys("abc123");
}
編輯
如果你想從給定數目的選擇內頁框內的唯一區別是src,那麼你可以使用這個:
driver.SwitchTo().Frame(driver.FindElement(By.CssSelector("iframe[src=\"test.aspx\"]")));
我想使用第二種方法訪問iframe,使用cssselector但src正在動態變化。