gpt4 book ai didi

java - Webdriver - 与远程浏览器通信时出错

转载 作者:行者123 更新时间:2023-12-01 12:53:45 25 4
gpt4 key购买 nike

即使在多次等待等之后,我仍然不断收到以下错误。我目前使用的是 Firefox 26.0 并收到以下错误。当条件为真时,测试工作正常,但如果检查 html 中的子字符串时的条件为假,则失败总是给出此错误。出现这个奇怪错误的原因是什么。我想显示正确的错误。

令人惊讶的是,测试在我的笔记本电脑(Linux mint)上运行良好。服务器有ubuntu和firefox 26.0

    String abc = wd.findElement(By.tagName("html")).getText();
System.out.println(abc);
if (!abc.contains("Narendra Modiii")) {
System.out.println("came here");
File scrFile = ((TakesScreenshot)wd).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("failedscreenshot.png"));

又恢复正常了

    String abc = wd.findElement(By.tagName("html")).getText();
System.out.println(abc);
if (!abc.contains("Narendra Modiii")) {
// System.out.println("came here");
File scrFile = ((TakesScreenshot)wd).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("failedscreenshot.png"));

给出以下异常

Jun 04, 2014 10:20:55 AM org.apache.http.impl.client.DefaultRequestDirector tryExecute
INFO: I/O exception (org.apache.http.NoHttpResponseException) caught when processing request: The target server failed to respond
Jun 04, 2014 10:20:55 AM org.apache.http.impl.client.DefaultRequestDirector tryExecute
INFO: Retrying request

以下是我的 java webdriver 测试

public class classqb8ksladhq {
public static void main(String[] args) {
FirefoxDriver wd = null;
try {
String Xport = System.getProperty("lmportal.xvfb.id", ":1");
final File firefoxPath = new File(System.getProperty("lmportal.deploy.firefox.path",
"/usr/bin/firefox"));
FirefoxBinary firefoxBinary = new FirefoxBinary(firefoxPath);
firefoxBinary.setEnvironmentProperty("DISPLAY", Xport);
wd = new FirefoxDriver(firefoxBinary, null);
wd.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
wd.get("http://dev.scroll.in/");
wd.findElement(By.xpath("//div[@class='searchbox']/input")).click();
Thread.sleep(5*1000);
wd.findElement(By.xpath("//div[@class='searchbox']/input")).clear();
Thread.sleep(5*1000);
wd.findElement(By.xpath("//div[@class='searchbox']/input")).sendKeys("bjp");
Thread.sleep(60*1000);
if (!wd.findElement(By.tagName("html")).getText().contains("zzzzzzzz")) {
File scrFile = ((TakesScreenshot)wd).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("failedscreenshot.png"));

throw new RuntimeException("!wd.findElement(By.tagName(\"html\")).getText().contains(\"Narendra Modiii\") is false");
}
System.out.println("Test ran successfully.");
}
catch (Exception e) {
try{
File scrFile = ((TakesScreenshot)wd).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("failedscreenshot.png"));
e.printStackTrace();
} catch(Exception e1) {
}
}
}
//wd.quit()
}

最佳答案

假设是因为超时问题,检查Configuring timeouts

关于java - Webdriver - 与远程浏览器通信时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24032776/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com