我在firefox驱动程序上运行硒测试时遇到问题。问题是驱动程序没有导航到新选项卡。它会打开选项卡,但是流程并没有转移。这些是我在pom中使用的依赖项:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>2.2.0</version>
</dependency>
这是我正在创建的firefox驱动程序的实例-
FirefoxDriverManager.getInstance().setup();
driver = new FirefoxDriver();
这是导入-
import io.github.bonigarcia.wdm.FirefoxDriverManager;
这是我用来导航到新窗口的代码。
public void switchToNewWindow() {
parentWindow = driver.getWindowHandle();
Set<String> handles = driver.getWindowHandles();
for (String windowHandle : handles) {
if (!windowHandle.equals(parentWindow)) {
driver.switchTo().window(windowHandle);
driver.manage().window().maximize();
}
}
}
测试在chrome浏览器上运行正常,没有任何问题。
这是firefox浏览器的版本-
Version 61.0.2 (64-bit)
这是错误消息。未能检测到的定位器位于新选项卡中,驱动程序未能将其切换到-
Testing started at 16:03 ...
"C:\Program Files\Java\jdk1.8.0_161\bin\java" -Dorg.jetbrains.run.directory=C:\Users\rajeshg\IdeaProjects\nxtier\src\test\Resources\com\unionstreet\NxTier\smokePack "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2017.3.4\lib\idea_rt.jar=52489:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2017.3.4\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_161\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_161\jre\lib\rt.jar;C:\Users\rajeshg\IdeaProjects\nxtier\target\test-classes;C:\Users\rajeshg\IdeaProjects\nxtier\target\classes;C:\Users\rajeshg\.m2\repository\com\google\guava\guava\23.0\guava-23.0.jar;C:\Users\rajeshg\.m2\repository\com\google\code\findbugs\jsr305\1.3.9\jsr305-1.3.9.jar;C:\Users\rajeshg\.m2\repository\com\google\errorprone\error_prone_annotations\2.0.18\error_prone_annotations-2.0.18.jar;C:\Users\rajeshg\.m2\repository\com\google\j2objc\j2objc-annotations\1.1\j2objc-annotations-1.1.jar;C:\Users\rajeshg\.m2\repository\org\codehaus\mojo\animal-sniffer-annotations\1.14\animal-sniffer-annotations-1.14.jar;C:\Users\rajeshg\.m2\repository\com\jayway\restassured\rest-assured\2.9.0\rest-assured-2.9.0.jar;C:\Users\rajeshg\.m2\repository\org\codehaus\groovy\groovy\2.4.4\groovy-2.4.4.jar;C:\Users\rajeshg\.m2\repository\org\codehaus\groovy\groovy-xml\2.4.4\groovy-xml-2.4.4.jar;C:\Users\rajeshg\.m2\repository\org\apache\httpcomponents\httpclient\4.5.1\httpclient-4.5.1.jar;C:\Users\rajeshg\.m2\repository\org\apache\httpcomponents\httpmime\4.5.1\httpmime-4.5.1.jar;C:\Users\rajeshg\.m2\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;C:\Users\rajeshg\.m2\repository\org\hamcrest\hamcrest-library\1.3\hamcrest-library-1.3.jar;C:\Users\rajeshg\.m2\repository\org\ccil\cowan\tagsoup\tagsoup\1.2.1\tagsoup-1.2.1.jar;C:\Users\rajeshg\.m2\repository\com\jayway\restassured\json-path\2.9.0\json-path-2.9.0.jar;C:\Users\rajeshg\.m2\repository\org\codehaus\groovy\groovy-json\2.4.4\groovy-json-2.4.4.jar;C:\Users\rajeshg\.m2\repository\com\jayway\restassured\rest-assured-common\2.9.0\rest-assured-common-2.9.0.jar;C:\Users\rajeshg\.m2\repository\com\jayway\restassured\xml-path\2.9.0\xml-path-2.9.0.jar;C:\Users\rajeshg\.m2\repository\com\jayway\jsonpath\json-path\2.4.0\json-path-2.4.0.jar;C:\Users\rajeshg\.m2\repository\net\minidev\json-smart\2.3\json-smart-2.3.jar;C:\Users\rajeshg\.m2\repository\net\minidev\accessors-smart\1.2\accessors-smart-1.2.jar;C:\Users\rajeshg\.m2\repository\org\ow2\asm\asm\5.0.4\asm-5.0.4.jar;C:\Users\rajeshg\.m2\repository\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;C:\Users\rajeshg\.m2\repository\org\hamcrest\hamcrest-all\1.3\hamcrest-all-1.3.jar;C:\Users\rajeshg\.m2\repository\com\googlecode\json-simple\json-simple\1.1.1\json-simple-1.1.1.jar;C:\Users\rajeshg\.m2\repository\junit\junit\4.12\junit-4.12.jar;C:\Users\rajeshg\.m2\repository\io\github\bonigarcia\webdrivermanager\2.2.0\webdrivermanager-2.2.0.jar;C:\Users\rajeshg\.m2\repository\commons-io\commons-io\2.5\commons-io-2.5.jar;C:\Users\rajeshg\.m2\repository\com\google\code\gson\gson\2.8.0\gson-2.8.0.jar;C:\Users\rajeshg\.m2\repository\org\rauschig\jarchivelib\0.7.1\jarchivelib-0.7.1.jar;C:\Users\rajeshg\.m2\repository\org\apache\commons\commons-compress\1.9\commons-compress-1.9.jar;C:\Users\rajeshg\.m2\repository\org\jsoup\jsoup\1.10.2\jsoup-1.10.2.jar;C:\Users\rajeshg\.m2\repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;C:\Users\rajeshg\.m2\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;C:\Users\rajeshg\.m2\repository\com\vimalselvam\cucumber-extentsreport\1.0.0\cucumber-extentsreport-1.0.0.jar;C:\Users\rajeshg\.m2\repository\info\cukes\cucumber-java\1.2.3\cucumber-java-1.2.3.jar;C:\Users\rajeshg\.m2\repository\com\relevantcodes\extentreports\2.40.2\extentreports-2.40.2.jar;C:\Users\rajeshg\.m2\repository\org\xerial\sqlite-jdbc\3.8.11.1\sqlite-jdbc-3.8.11.1.jar;C:\Users\rajeshg\.m2\repository\org\freemarker\freemarker\2.3.23\freemarker-2.3.23.jar;C:\Users\rajeshg\.m2\repository\org\apache\directory\studio\org.apache.commons.codec\1.8\org.apache.commons.codec-1.8.jar;C:\Users\rajeshg\.m2\repository\org\seleniumhq\selenium\selenium-java\3.14.0\selenium-java-3.14.0.jar;C:\Users\rajeshg\.m2\repository\org\seleniumhq\selenium\selenium-chrome-driver\3.14.0\selenium-chrome-driver-3.14.0.jar;C:\Users\rajeshg\.m2\repository\org\seleniumhq\selenium\selenium-edge-driver\3.14.0\selenium-edge-driver-3.14.0.jar;C:\Users\rajeshg\.m2\repository\org\seleniumhq\selenium\selenium-firefox-driver\3.14.0\selenium-firefox-driver-3.14.0.jar;C:\Users\rajeshg\.m2\repository\org\seleniumhq\selenium\selenium-ie-driver\3.14.0\selenium-ie-driver-3.14.0.jar;C:\Users\rajeshg\.m2\repository\org\seleniumhq\selenium\selenium-opera-driver\3.14.0\selenium-opera-driver-3.14.0.jar;C:\Users\rajeshg\.m2\repository\org\seleniumhq\selenium\selenium-remote-driver\3.14.0\selenium-remote-driver-3.14.0.jar;C:\Users\rajeshg\.m2\repository\org\seleniumhq\selenium\selenium-safari-driver\3.14.0\selenium-safari-driver-3.14.0.jar;C:\Users\rajeshg\.m2\repository\org\seleniumhq\selenium\selenium-support\3.14.0\selenium-support-3.14.0.jar;C:\Users\rajeshg\.m2\repository\net\bytebuddy\byte-buddy\1.8.15\byte-buddy-1.8.15.jar;C:\Users\rajeshg\.m2\repository\org\apache\commons\commons-exec\1.3\commons-exec-1.3.jar;C:\Users\rajeshg\.m2\repository\commons-codec\commons-codec\1.10\commons-codec-1.10.jar;C:\Users\rajeshg\.m2\repository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;C:\Users\rajeshg\.m2\repository\org\apache\httpcomponents\httpcore\4.4.9\httpcore-4.4.9.jar;C:\Users\rajeshg\.m2\repository\com\squareup\okhttp3\okhttp\3.10.0\okhttp-3.10.0.jar;C:\Users\rajeshg\.m2\repository\com\squareup\okio\okio\1.14.1\okio-1.14.1.jar;C:\Users\rajeshg\.m2\repository\org\apache\commons\commons-lang3\3.4\commons-lang3-3.4.jar;C:\Users\rajeshg\.m2\repository\net\sourceforge\htmlunit\htmlunit\2.18\htmlunit-2.18.jar;C:\Users\rajeshg\.m2\repository\xalan\xalan\2.7.2\xalan-2.7.2.jar;C:\Users\rajeshg\.m2\repository\xalan\serializer\2.7.2\serializer-2.7.2.jar;C:\Users\rajeshg\.m2\repository\commons-collections\commons-collections\3.2.1\commons-collections-3.2.1.jar;C:\Users\rajeshg\.m2\repository\net\sourceforge\htmlunit\htmlunit-core-js\2.17\htmlunit-core-js-2.17.jar;C:\Users\rajeshg\.m2\repository\xerces\xercesImpl\2.11.0\xercesImpl-2.11.0.jar;C:\Users\rajeshg\.m2\repository\xml-apis\xml-apis\1.4.01\xml-apis-1.4.01.jar;C:\Users\rajeshg\.m2\repository\net\sourceforge\nekohtml\nekohtml\1.9.22\nekohtml-1.9.22.jar;C:\Users\rajeshg\.m2\repository\net\sourceforge\cssparser\cssparser\0.9.16\cssparser-0.9.16.jar;C:\Users\rajeshg\.m2\repository\org\w3c\css\sac\1.3\sac-1.3.jar;C:\Users\rajeshg\.m2\repository\org\eclipse\jetty\websocket\websocket-client\9.2.12.v20150709\websocket-client-9.2.12.v20150709.jar;C:\Users\rajeshg\.m2\repository\org\eclipse\jetty\jetty-util\9.2.12.v20150709\jetty-util-9.2.12.v20150709.jar;C:\Users\rajeshg\.m2\repository\org\eclipse\jetty\jetty-io\9.2.12.v20150709\jetty-io-9.2.12.v20150709.jar;C:\Users\rajeshg\.m2\repository\org\eclipse\jetty\websocket\websocket-common\9.2.12.v20150709\websocket-common-9.2.12.v20150709.jar;C:\Users\rajeshg\.m2\repository\org\eclipse\jetty\websocket\websocket-api\9.2.12.v20150709\websocket-api-9.2.12.v20150709.jar;C:\Users\rajeshg\.m2\repository\net\sourceforge\jtds\jtds\1.3.1\jtds-1.3.1.jar;C:\Users\rajeshg\.m2\repository\xmlunit\xmlunit\1.6\xmlunit-1.6.jar;C:\Users\rajeshg\.m2\repository\com\microsoft\sqlserver\mssql-jdbc\6.1.0.jre8\mssql-jdbc-6.1.0.jre8.jar;C:\Users\rajeshg\.m2\repository\com\microsoft\azure\azure-keyvault\0.9.3\azure-keyvault-0.9.3.jar;C:\Users\rajeshg\.m2\repository\com\microsoft\azure\azure-core\0.9.3\azure-core-0.9.3.jar;C:\Users\rajeshg\.m2\repository\commons-lang\commons-lang\2.6\commons-lang-2.6.jar;C:\Users\rajeshg\.m2\repository\javax\mail\mail\1.4.5\mail-1.4.5.jar;C:\Users\rajeshg\.m2\repository\javax\activation\activation\1.1\activation-1.1.jar;C:\Users\rajeshg\.m2\repository\com\sun\jersey\jersey-client\1.13\jersey-client-1.13.jar;C:\Users\rajeshg\.m2\repository\com\sun\jersey\jersey-core\1.13\jersey-core-1.13.jar;C:\Users\rajeshg\.m2\repository\com\sun\jersey\jersey-json\1.13\jersey-json-1.13.jar;C:\Users\rajeshg\.m2\repository\org\codehaus\jettison\jettison\1.1\jettison-1.1.jar;C:\Users\rajeshg\.m2\repository\com\sun\xml\bind\jaxb-impl\2.2.3-1\jaxb-impl-2.2.3-1.jar;C:\Users\rajeshg\.m2\repository\javax\xml\bind\jaxb-api\2.2.2\jaxb-api-2.2.2.jar;C:\Users\rajeshg\.m2\repository\javax\xml\stream\stax-api\1.0-2\stax-api-1.0-2.jar;C:\Users\rajeshg\.m2\repository\org\codehaus\jackson\jackson-core-asl\1.9.2\jackson-core-asl-1.9.2.jar;C:\Users\rajeshg\.m2\repository\org\codehaus\jackson\jackson-mapper-asl\1.9.2\jackson-mapper-asl-1.9.2.jar;C:\Users\rajeshg\.m2\repository\org\codehaus\jackson\jackson-jaxrs\1.9.2\jackson-jaxrs-1.9.2.jar;C:\Users\rajeshg\.m2\repository\org\codehaus\jackson\jackson-xc\1.9.2\jackson-xc-1.9.2.jar;C:\Users\rajeshg\.m2\repository\javax\inject\javax.inject\1\javax.inject-1.jar;C:\Users\rajeshg\.m2\repository\com\microsoft\azure\adal4j\1.0.0\adal4j-1.0.0.jar;C:\Users\rajeshg\.m2\repository\com\nimbusds\oauth2-oidc-sdk\4.5\oauth2-oidc-sdk-4.5.jar;C:\Users\rajeshg\.m2\repository\net\jcip\jcip-annotations\1.0\jcip-annotations-1.0.jar;C:\Users\rajeshg\.m2\repository\com\nimbusds\lang-tag\1.4\lang-tag-1.4.jar;C:\Users\rajeshg\.m2\repository\com\nimbusds\nimbus-jose-jwt\3.1.2\nimbus-jose-jwt-3.1.2.jar;C:\Users\rajeshg\.m2\repository\org\bouncycastle\bcprov-jdk15on\1.51\bcprov-jdk15on-1.51.jar;C:\Users\rajeshg\.m2\repository\info\cukes\cucumber-junit\1.2.5\cucumber-junit-1.2.5.jar;C:\Users\rajeshg\.m2\repository\info\cukes\cucumber-core\1.2.5\cucumber-core-1.2.5.jar;C:\Users\rajeshg\.m2\repository\info\cukes\cucumber-html\0.2.3\cucumber-html-0.2.3.jar;C:\Users\rajeshg\.m2\repository\info\cukes\cucumber-jvm-deps\1.0.5\cucumber-jvm-deps-1.0.5.jar;C:\Users\rajeshg\.m2\repository\info\cukes\gherkin\2.12.2\gherkin-2.12.2.jar;C:\Users\rajeshg\.m2\repository\org\apache\pdfbox\pdfbox\2.0.0\pdfbox-2.0.0.jar;C:\Users\rajeshg\.m2\repository\org\apache\pdfbox\fontbox\2.0.0\fontbox-2.0.0.jar;C:\Users\rajeshg\.m2\repository\mysql\mysql-connector-java\6.0.4\mysql-connector-java-6.0.4.jar;C:\Users\rajeshg\.m2\repository\de\redsix\pdfcompare\1.1.25\pdfcompare-1.1.25.jar;C:\Users\rajeshg\.m2\repository\com\typesafe\config\1.3.1\config-1.3.1.jar;C:\Users\rajeshg\.m2\repository\org\dbunit\dbunit\2.5.4\dbunit-2.5.4.jar;C:\Users\rajeshg\.m2\repository\org\apache\poi\poi-ooxml\3.14\poi-ooxml-3.14.jar;C:\Users\rajeshg\.m2\repository\org\apache\poi\poi\3.14\poi-3.14.jar;C:\Users\rajeshg\.m2\repository\org\apache\poi\poi-ooxml-schemas\3.14\poi-ooxml-schemas-3.14.jar;C:\Users\rajeshg\.m2\repository\org\apache\xmlbeans\xmlbeans\2.6.0\xmlbeans-2.6.0.jar;C:\Users\rajeshg\.m2\repository\stax\stax-api\1.0.1\stax-api-1.0.1.jar;C:\Users\rajeshg\.m2\repository\com\github\virtuald\curvesapi\1.03\curvesapi-1.03.jar;C:\Users\rajeshg\.m2\repository\com\opencsv\opencsv\4.0\opencsv-4.0.jar;C:\Users\rajeshg\.m2\repository\org\apache\commons\commons-text\1.1\commons-text-1.1.jar;C:\Users\rajeshg\.m2\repository\commons-beanutils\commons-beanutils\1.9.3\commons-beanutils-1.9.3.jar;C:\Users\rajeshg\.m2\repository\org\seleniumhq\selenium\selenium-api\3.14.0\selenium-api-3.14.0.jar;C:\Users\rajeshg\.m2\repository\io\netty\netty\3.5.7.Final\netty-3.5.7.Final.jar;C:\Users\rajeshg\.IdeaIC2017.3\config\plugins\cucumber-java\lib\cucumber-jvm-formatter.jar" cucumber.api.cli.Main --plugin org.jetbrains.plugins.cucumber.java.run.CucumberJvmSMFormatter --monochrome --name "^Adding pricing details to a newly created customer$" --glue com.unionstreet.support --glue com.unionstreet.NxTier.stepDefs.smokePack C:/Users/rajeshg/IdeaProjects/nxtier/src/test/Resources/com/unionstreet/NxTier/smokePack/NxTier_smokePack.feature
16:03:51.767 [main] INFO io.github.bonigarcia.wdm.WebDriverManager - Reading https://api.github.com/repos/mozilla/geckodriver/releases to seek wires, geckodriver
16:03:52.126 [main] INFO io.github.bonigarcia.wdm.WebDriverManager - Latest version of wires, geckodriver is 0.21.0
16:03:52.157 [main] INFO io.github.bonigarcia.wdm.Downloader - Using binary driver previously downloaded C:\Users\rajeshg\.m2\repository\webdriver\geckodriver\win64\0.21.0\geckodriver.exe
16:03:52.157 [main] DEBUG io.github.bonigarcia.wdm.Downloader - Target folder content: geckodriver.exe
16:03:52.157 [main] INFO io.github.bonigarcia.wdm.Downloader - Using binary driver previously downloaded C:\Users\rajeshg\.m2\repository\webdriver\geckodriver\win64\0.21.0\geckodriver.exe
16:03:52.157 [main] INFO io.github.bonigarcia.wdm.WebDriverManager - Exporting webdriver.gecko.driver as C:\Users\rajeshg\.m2\repository\webdriver\geckodriver\win64\0.21.0\geckodriver.exe
1533827032298 geckodriver INFO geckodriver 0.21.0
1533827032314 geckodriver INFO Listening on 127.0.0.1:27819
1533827032954 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "-marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\rajeshg\\AppData\\Local\\Temp\\rust_mozprofile.DpjbO1o8RyAk"
Unable to read VR Path Registry from C:\Users\rajeshg\AppData\Local\openvr\openvrpaths.vrpath
Unable to read VR Path Registry from C:\Users\rajeshg\AppData\Local\openvr\openvrpaths.vrpath
Unable to read VR Path Registry from C:\Users\rajeshg\AppData\Local\openvr\openvrpaths.vrpath
Unable to read VR Path Registry from C:\Users\rajeshg\AppData\Local\openvr\openvrpaths.vrpath
Unable to read VR Path Registry from C:\Users\rajeshg\AppData\Local\openvr\openvrpaths.vrpath
1533827034578 Marionette INFO Listening on port 52497
1533827034618 Marionette WARN TLS certificate errors will be ignored for this session
Aug 09, 2018 4:03:54 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
org.openqa.selenium.TimeoutException: Expected condition failed: waiting for element to be clickable: By.id: DCompany_name (tried for 20 second(s) with 500 milliseconds interval)
at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:113)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:283)
at com.unionstreet.support.ElementUtils.sendText(ElementUtils.java:70)
at com.unionstreet.com.unionstreet.NxTier.pages.NewBusinessCustomerPage.addCompanyInfoForNewBusinessCustomerCreatedWithDefaultContactTypes(NewBusinessCustomerPage.java:65)
at com.unionstreet.NxTier.stepDefs.smokePack.NxTier_smokePack_stepDefs.iHaveAddedANewBusinessCustomer(NxTier_smokePack_stepDefs.java:79)
at ✽.And I have added a new business customer(C:/Users/rajeshg/IdeaProjects/nxtier/src/test/Resources/com/unionstreet/NxTier/smokePack/NxTier_smokePack.feature:45)
Caused by: org.openqa.selenium.NoSuchElementException: Cannot locate an element using By.id: DCompany_name
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
System info: host: 'TESTING001', ip: '10.1.8.93', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_161'
Driver info: driver.version: unknown
任何帮助将不胜感激! 谢谢!
答案 0 :(得分:0)
100%工作解决方案:
// open new tab
Robot rob = new Robot();
rob.keyPress(KeyEvent.VK_CONTROL);
rob.keyPress(KeyEvent.VK_T);
rob.keyRelease(KeyEvent.VK_CONTROL);
rob.keyRelease(KeyEvent.VK_T);
// wait to winHandles value increases. Without it will result in random nullPointerException at this point.
Thread.sleep(100);
// get fresh winHandles to ArrayList
ArrayList<String> winHandles = new ArrayList<String> (driver.getWindowHandles());
// select tab by index
driver.switchTo().window(winHandles.get(1));
// continue on the new tab
答案 1 :(得分:0)
1)首先,您需要检索打开的标签页
List<String> tabs = new ArrayList<>(driver.getWindowHandles());
2)打开新标签
((JavascriptExecutor)driver).executeScript("window.open('/')");
3)导航至标签页
driver.switchTo.window(tabs.get(index))