【问题标题】:Timeout error in TestNGTestNG 中的超时错误
【发布时间】: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


【解决方案1】:

用下面提到的代码替换您的 @Test 方法代码。

    WebDriverWait wait = new WebDriverWait (driver, 20);
    WebElement w= 
            wait.until(ExpectedConditions.elementToBeClickable(By.id("lst-ib")));
    w.sendKeys("Shirt"); 
    driver.findElement(By.id("_fZl")).click();

让我知道它是否适合你。

【讨论】:

  • 它成功了。谢谢 Akarsh。我猜 xpatg 不正确。但我是直接从 firebug 那里得到的。
  • 您编写的 Xpath 很好,但是您使用的 id 具有属性 aria-hidden="true",可能是该 id 被隐藏了。我不确定。
【解决方案2】:

我认为在您的 html 页面中找不到该元素,可能您的 xpath 不正确。您可以尝试使用 chrome 开发人员工具 > 控制台选项卡检查它,然后键入 $x(". //[@id='gs_htif0']") 并查看它是否返回任何内容。也许你的 xpath 应该是 "//[@id='gs_htif0']"

【讨论】:

    猜你喜欢
    • 2013-05-29
    • 2020-02-07
    • 1970-01-01
    • 2021-09-28
    • 1970-01-01
    • 2014-02-28
    • 2017-07-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多