0
在我的項目有一個iframe ID爲改變我們對試圖找到硒動態的iframe頁面的webdriver
點擊我嘗試了許多方法來工作,每一次在那
1) List<WebElement> frameList=driver.findElements(By.tagName("iframe"));
System.out.println(frameList.size());
for(int i =0; i<(frameList.size());i++){
driver.switchTo().frame(i);
System.out.println(i);
try{
driver.findElement(By.id("TextBox_4")).sendKeys("987654321");
System.out.println("Element found");
}
catch (NoSuchElementException e){
System.out.println("Element not found");
}
//這將檢查iframe中的元素。
2) WebElement frame =
driver.findElement(By.xpath("//div[contains(@id,'title')]"));
driver.switchTo().frame(frame);
//使用XPath和該搜索幀中包含關鍵字,但其示出了元件未發現異常
3) int frameSize = driver.findElements(By.tagName("iframe")).size();
System.out.println(frameSize);
driver.switchTo().frame(2);
//我打印幀的大小(即,3個),並試圖每個幀值(即0,1,2)
請更正以上代碼。
感謝 迪瓦卡爾
什麼是IFRAME的ID的一些例子,例如它如何改變?無論如何,可能有辦法訪問它。 IFRAME是否總是在HTML中的相同位置?例如在一些可以一致標識的元素內? – JeffC
除了JeffC所說的內容,請與我們分享您的網頁。沒有任何細節,它很難提供幫助。 – testerjoe2
嘗試使用** [frameToBeAvailableAndSwitchToIt](https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/support/ui/ExpectedConditions.html#frameToBeAvailableAndSwitchToIt-org.openqa.selenium.By - )**方法通過應用[顯式等待](http://stackoverflow.com/a/14515517/4193730)。它寧願爲你簡化一些事情。首先要在Firebug的HTML選項卡中找到iframe,爲iFrame製作xpath,然後使用上述方法。 – Subh