嘗試這樣:
public static int DEFAULT_IMPLICIT_WAIT = 30;
getElementByLocator(By.cssSelector("span.ui-icon.ui-icon-closethick")).click();
從這個方法:
public static WebElement getElementByLocator(By locator) {
long startTime = System.currentTimeMillis();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
WebElement we = null;
boolean unfound = true;
while (unfound) {
try {
we = driver.findElement(locator);
unfound = false; // FOUND IT
} catch (StaleElementReferenceException e) {
unfound = true;
try {
Thread.sleep(4000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
// and finally the cleanup
driver.manage().timeouts().implicitlyWait(DEFAULT_IMPLICIT_WAIT, TimeUnit.SECONDS);
return we;
}
公共類Frame_demo { 公共靜態無效的主要(字串[] args){ webdriver的驅動=新FirefoxDriver(); driver.manage()。timeouts()。implicitlyWait(10,TimeUnit.SECONDS); driver.get(「http://www.makemytrip.com/」); driver.findElement(By.linkText(「Cancellation」))。click(); WebElement cframe = driver.findElement(By.xpath(「// iframe [@ id ='dlgov']」)); driver.switchTo().frame(cframe); (「//輸入[@ id ='bookingID']」))。sendKeys(「abcd」); driver.findElement(By.xpath(「// span // a」))。click(); driver.switchTo()。defaultContent(); \t //這是代碼ü可以運行2 C錯誤 \t }} – 2013-03-15 20:20:21
你嘗試切換此行** driver.findElement(By.xpath( 「// //跨度一」))。點擊(); **這個** driver.findElement(By.cssSelector(「span.ui-icon.ui-icon-closethick」))。click(); **? – monteirobrena 2013-03-15 20:26:35
是的,但它沒有工作 – 2013-03-15 20:28:09