虽然FirefoxDriver工作,Selenium Htmlunitdriver无法正常工作

时间:2017-03-25 14:31:32

标签: selenium htmlunit-driver

为什么这段代码会使用HtmlUnitDriver产生“失败”,而使用FirefoxDriver产生“成功”?它试图捕获在页面其余部分之后加载几秒钟的文本。我需要使用HtmlUnitDriver“成功”。

$product = new Product;


if($product->is_on_sale())

1 个答案:

答案 0 :(得分:0)

请尝试以下代码:

  for (int i = 0; i < 360; i++) 
            if (driver.getPageSource().contains("<span id=\"availability")) {
                Thread.sleep(500);
                break;
            }

     String e = driver.findElement(By.xpath("//strong[contains(text(),'1 business day')]")).getText();
     System.out.println(e);
            Thread.sleep(500);
            if (e.contains("1 business day"))
                System.out.println("Success");
            else
                System.out.println("Failure");

还要单独获取它们:尝试按照

  

第一行:

String a = driver.findElement(By.xpath("//div[@id='ships-from-lead-time-G1237047'][@class='ships-from-lead-time']")).getText();
String b = driver.findElement(By.xpath(".//strong[contains(text(),'1 business day.')]")).getText();
System.out.println(a);
System.out.println(b);
  

第二行:

String c =driver.findElement(By.xpath("//span[@id='price-box-ships-free']")).getText();
System.out.println(c);
  

第三行:

String d = driver.findElement(By.xpath("//span[@id='price-box-standard-ground']")).getText();
System.out.println(d);