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();
}}
得到如下錯誤:超時錯誤TestNG中
FAILED: main org.openqa.selenium.TimeoutException: Timed out after 20 seconds waiting for element to be clickable: By.xpath: .//*[@id='gs_htif0'] Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:37:09' Driver info: org.openqa.selenium.firefox.FirefoxDriver Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=46.0, platform=WINDOWS, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}] Session ID: 93e46eb2-2ba1-479b-9bfd-c56178d7eb7c at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:80) at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:261) at ant.NewTestNG.main(NewTestNG.java:28)
您可以進行一些小的更改並更新我的狀態,如下所示:1.刪除TestNG環境設置並嘗試作爲純Java程序執行? 2.在作爲TestNG Test/Suite執行Test with Test註釋時,您不得將方法名稱用作「main」,將其更改爲其他內容並將我的狀態更新。 – DebanjanB