当我从Eclipse运行Selenium脚本时,它运行良好。而当我从 Jenkins 运行相同的脚本时,会抛出如下错误: org.openqa.selenium.ElementClickInterceptedException:元素单击被拦截:元素...在点(763,142)不可单击。其他元素将获得点击:... 。
我尝试过WebDriverException: Element is not clickable at point。但是,不走运!
下面是我的代码:
@Test(priority=1)
public void verifyLoginTest() throws Exception {
driver.findElement(By.id("UserLogin")).click();
driver.findElement(By.id("UserLogin")).clear();
Thread.sleep(1000);
driver.findElement(By.id("UserLogin")).sendKeys(prop.getProperty("username"));
driver.findElement(By.id("PasswordHash")).clear();
driver.findElement(By.id("PasswordHash")).sendKeys(prop.getProperty("password"));
driver.findElement(By.id("btnok")).click();
Thread.sleep(1000);
}
@Test(priority=2)
public void verifyHomePageTest() throws Exception {
// driver.findElement(By.xpath("(.//*[normalize-space(text()) and normalize-space(.)='Employment History and Employee Master'])[1]/preceding::h4[1]")).click();
driver.findElement(By.linkText("Maintenance")).click();
Thread.sleep(1000);
}
@Test(priority=3)
public void testCreateNewUser() throws Exception {
// driver.findElement(By.xpath("(.//*[normalize-space(text()) and normalize-space(.)='Employment History and Employee Master'])[1]/preceding::h4[1]")).click();
driver.findElement(By.linkText("User Maintenance")).click();
ArrayList<String> tabs = new ArrayList <String>(driver.getWindowHandles());
System.out.println("Window Names: "+tabs);
driver.switchTo().window(tabs.get(1));
driver.findElement(By.id("lbtnAddNewBenefitTier")).click();
Thread.sleep(1000);
driver.findElement(By.id("UserLogin")).click();//
driver.findElement(By.id("UserLogin")).clear();
driver.findElement(By.id("UserLogin")).sendKeys(prop.getProperty("UserLogin"));
Thread.sleep(1000);
TetsBase.java类:
System.setProperty("webdriver.chrome.driver", chrome.getAbsolutePath());
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-features=VizDisplayCompositor");
options.addArguments("--headless");
options.addArguments("--no-sandbox");
options.addArguments("--window-size=1920,1080");
options.addArguments("--disable-browser-side-navigation");
options.addArguments("--disable-gpu");
options.addArguments("--disable-extensions");
options.addArguments("--dns-prefetch-disable");
options.setPageLoadStrategy(PageLoadStrategy.NONE);
我能够在Eclipse的Headless模式下成功运行相同的脚本。
Chrome网络浏览器中的检查元素为:<a class="btn btn-AddNewGridRow" id="lbtnAddNewBenefitTier" onclick="AddNewRow_usergrid()" tabindex="8" style="margin-right: 30px;">Create New User</a>
注意:要检查同一脚本是否可以在无头模式下成功运行,我在Test Base类中添加了以上代码。通常,当我在Eclipse中运行时,我会注释掉无头模式,“窗口大小”命令,并将在Jenkins中运行。 如何从詹金斯成功运行脚本