在makemytrip.com中点击取消链接,会打开一个新框架,显示“取消您的航班预订”,这是一个框架。在此框架中,我正在尝试单击“关闭此窗口”链接。但这并没有发生,在eclipse中它给出了元素不存在的错误。
这是代码,
driver.findElement(By.xpath("//div[@class='dialog_closepanel']//span//a[text()='close this window']")).click();
如何点击此链接?
答案 0 :(得分:0)
试试这段代码:
driver.findElement(By.cssSelector("span.ui-icon.ui-icon-closethick")).click();
编辑:
如果您看到关闭模式的链接和图标,请尝试以下操作:
driver.findElement(By.linkText("close this window")).click();
或者
driver.findElement(By.cssSelector("img[alt=\"close\"]")).click();
答案 1 :(得分:0)
尝试这样的事情:
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;
}