IE的元素没有得到点击在第一时间使用硒的webdriver
问题描述:
我想点击一个链接,在IE 11,并使用下面的代码:IE的元素没有得到点击在第一时间使用硒的webdriver
driver.findElement(By.xpath("//a[text()='En savoir plus']")).click();
我没有得到任何异常,但页面是没有得到任何地方导航,它也冻结了整个页面,我不能够继续。
我遇到了同样的问题,几年前,我记得的解决方案是使用相同的命令两次:
driver.findElement(By.xpath("//a[text()='En savoir plus']")).click();
driver.findElement(By.xpath("//a[text()='En savoir plus']")).click();
这会点击链接成功地不结冰的页面。
有没有解决这个问题的方法?
答
也许这将帮助?
try {
WebElement yourElement = driver.findElement(By.xpath("//a[text()='En savoir plus']"));
if (yourElement.isEnabled() && yourElement.isDisplayed()) {
System.out.println("Clicking on element with using javascript click");
((JavascriptExecutor) driver).executeScript("arguments[0].click();", yourElement);
} else {
System.out.println("Unable to click on element");
}
} catch (StaleElementReferenceException e) {
System.out.println("Element is not attached to the page document "+ e.getStackTrace());
} catch (NoSuchElementException e) {
System.out.println("Element was not found in DOM "+ e.getStackTrace());
} catch (Exception e) {
System.out.println("Unable to click on element "+ e.getStackTrace());
}
}
}
答
尝试以下代码,使用javascript executor
方法。
注: -之前要点击这个按钮,提供wait
几秒钟让你的驱动程序可能能够找到webelement
。
对于wait
我使用Explicit Wait
方法。
new WebDriverWait(driver, 60).until(ExpectedConditions.elementToBeClickable(driver.findElement(By.xpath("//a[text()='En savoir plus']")))); //wait for 60 seconds.
WebElement button = driver.findElement(By.xpath("//a[text()='En savoir plus']"));
((JavascriptExecutor) driver).executeScript("arguments[0].click();", button);
+0
你试过这段代码吗?它对你有用吗? –
尝试使用javascriptExecutor并单击它 – iamsankalp89