【发布时间】:2017-04-17 10:07:53
【问题描述】:
package ant;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
public class NewTestNG {
public WebDriver driver;
@BeforeMethod
public void LAunchbrowser() {
driver = new FirefoxDriver();
driver.get("https://www.google.co.in/");
//driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
@Test
public void main() {
Actions action = new Actions(driver);
WebDriverWait wait = new WebDriverWait (driver, 20);
WebElement w=
wait.until(ExpectedConditions.elementToBeClickable(By.xpath(".//*
[@id='gs_htif0']")));
WebElement a= driver.findElement(By.xpath(".//*[@id='gs_htif0']"));
action.moveToElement(a).click().sendKeys("Shirt").build().perform();
driver.findElement(By.xpath("//div[@value='Search']")).click();
}}
出现以下错误:
失败:主要 org.openqa.selenium.TimeoutException: 等待元素可点击 20 秒后超时:By.xpath: .//*[@id='gs_htif0'] 构建信息:版本:'2.53.1',修订:'a36b8b1',时间:'2016-06-30 17:37:09' 驱动信息:org.openqa.selenium.firefox.FirefoxDriver 功能 [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=46.0, platform=WINDOWS, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takeScreenshot=true , javascriptEnabled=true, cssSelectorsEnabled=true}] 会话 ID:93e46eb2-2ba1-479b-9bfd-c56178d7eb7c 在 org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:80) 在 org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:261) 在 ant.NewTestNG.main(NewTestNG.java:28)
【问题讨论】:
-
你能做一些小的改动并更新我的状态如下: 1.删除TestNG环境设置并尝试作为纯Java程序执行吗? 2. 在作为带有 Test 注释的 TestNG 测试/套件执行时,您不能将方法名称用作“main”,将其更改为其他名称并更新状态。
标签: selenium testing timeoutexception