【问题标题】:Wait for a webelement to appear and keep clicking until that element appears等待 web 元素出现并继续单击,直到该元素出现
【发布时间】:2017-07-24 13:05:21
【问题描述】:

我陷入了一种奇怪的逻辑。 我的要求如下

  1. 保存信息
  2. 点击刷新按钮
  3. 等待查询 ID 出现
  4. If(3) 不为真,等待 10 秒,然后再次触发 Step(2) 除非出现查询 ID,否则保持 4 循环

查询ID是六位数,所以我正在使用

WebElement getInquiryId=driver.findElement(By.xpath("//a[contains(text(),'^\d{6}$')]"));

请根据以下要求帮助我构建 selenium 代码

【问题讨论】:

  • 可以添加查询id元素的html代码吗?
  • 参考这可能对stackoverflow.com/questions/45232461/…有帮助
  • 默认情况下保存信息不会邀请刷新吗?接下来我们可以等待 10 秒,让查询 id 循环消失。谢谢

标签: selenium wait


【解决方案1】:

这将是您的第 4 步代码:

while(!getInquiryId.isDisplayed()){
  try {
    Thread.sleep(10000); //wait for 10 seconds
  } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }
  if(getInquiryId.isDisplayed()){
    break;
  }else{
    refreshButton.click();
  }
}

【讨论】:

    猜你喜欢
    • 2020-03-29
    • 2018-01-12
    • 2016-05-09
    • 2013-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多