我正在尝试验证PDF的内容。 在我们的应用程序中,当我们单击链接时,将打开一个新选项卡,其中嵌入了pdf [新选项卡中没有URL],我的任务是验证PDF的内容。
我正在尝试切换到新的PDF并执行Ctrl + A和Ctrl + c,如下所示。
ArrayList<String> tabs = new ArrayList<String> (driver.getWindowHandles());
for (String string : tabs) {
System.out.println("tab id:: "+string);
}
driver.switchTo().window(tabs.get(1));
driver.switchTo().defaultContent();
System.out.println(driver.switchTo().window(tabs.get(0)).getTitle()); //first tab title
System.out.println(driver.switchTo().window(tabs.get(1)).getTitle()); //second tab title
String selectAll = Keys.chord(Keys.CONTROL,Keys.chord("a"));
String copy = Keys.chord(Keys.CONTROL,Keys.chord("c"));
//driver.switchTo().defaultContent();
pause(3000);
Actions action = new Actions(driver);
action.sendKeys(selectAll).perform();
pause(3000);
new Actions(driver).sendKeys(copy).build().perform();
但是当我尝试使用新标签执行任何活动时,我会遇到异常。 的System.out.println(driver.switchTo()窗口(tabs.get(1))的getTitle());
以下是例外情况。
[1528016019.920][SEVERE]: Timed out receiving message from renderer: 40.000
[1528016019.925][SEVERE]: Timed out receiving message from renderer: -0.019
org.openqa.selenium.TimeoutException: timeout
(Session info: chrome=66.0.3359.181)
(Driver info: chromedriver=2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 41.16 seconds
Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46'
System info: host: 'D2RMHQN2', ip: '10.165.226.152', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_152'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73), userDataDir=C:\Users\SG0221~1\AppData\Local\Temp\scoped_dir10444_7193}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=66.0.3359.181, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=false, acceptInsecureCerts=false, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, setWindowRect=true, unexpectedAlertBehaviour=}]
Session ID: abb6795a426b25128731ab96ae8db7fd
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:701)
at org.openqa.selenium.remote.RemoteWebDriver.getTitle(RemoteWebDriver.java:320)
at com.resources.PDFReader.verifyPDFContent(PDFReader.java:106)
ChromeDriver版本= 2.35.528161 Chrome版本= 66.0.3359.181
任何人都遇到过这类问题,请让我知道解决方案。 谢谢。
答案 0 :(得分:2)
配置问题ChromeDriver 2.35支持Chrome v62-64
使用Chrome 66时需要ChromeDriver 2.39或2.38