org.openqa.selenium.WebDriverException: invalid argument: 'handle' must be a string while window handling with Selenium and Java in Linux
This error message...
org.openqa.selenium.WebDriverException: invalid argument: 'handle' must be a string
...implies that the handle which was passed as an argument needs to be a string.
Logically you are pretty close. Possibly the driver.getWindowHandles()
is getting executed too early even before the second window handle is getting created/recognized.
Solution
As a solution you need to induce WebDriverWait for numberOfWindowsToBe(2)
and you can use the following code block:
String mainWindowHandler = driver.getWindowHandle(); // store mainWindowHandler for future references
//line of code that opens a new TAB / Window
new WebDriverWait(driver, 5).until(ExpectedConditions.numberOfWindowsToBe(2)); //induce WebDriverWait
Set<String> handles = driver.getWindowHandles();
Iterator<String> iterator = handles.iterator();
while (iterator.hasNext())
{
String subWindowHandler = iterator.next();
if (!mainWindowHandler.equalsIgnoreCase(subWindowHandler))
{
driver.switchTo().window(subWindowHandler);
}
}
You can find a relevant detailed discussion in Best way to keep track and iterate through tabs and windows using WindowHandles using Selenium
How to handle new window, which opened automatically in new tab?
If it's a new window to count the number of WindowHandles you need to induce WebDriverWait for numberOfWindowsToBe(2)
and you can use the following code block:
String mainWindowHandler = driver.getWindowHandle(); // store mainWindowHandler for future references
//line of code that opens a new TAB / Window
new WebDriverWait(driver, 5).until(ExpectedConditions.numberOfWindowsToBe(2)); //induce WebDriverWait
Set<String> handles = driver.getWindowHandles();
Iterator<String> iterator = handles.iterator();
while (iterator.hasNext())
{
String subWindowHandler = iterator.next();
if (!mainWindowHandler.equalsIgnoreCase(subWindowHandler))
{
driver.switchTo().window(subWindowHandler);
}
}
References
You can find a couple of relevant detailed discussions in:
- Selenium switch focus to tab, which opened after clicking link
- Best way to keep track and iterate through tabs and windows using WindowHandles using Selenium
- org.openqa.selenium.WebDriverException: invalid argument: 'handle' must be a string while window handling with Selenium and Java in Linux
org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start. Build info: version: 'unknown', revision: 'unknown'
This error message...
2018-08-31 09:16:26,570 ERROR [io.undertow.request] (default task-1) UT005023: Exception handling request to /crawlerClass/myCrawler/5922: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
...implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.
Your base exception is the org.openqa.selenium.WebDriverException
as your program Timed out waiting for driver server to start
because of the following reason:
- Your JDK version is 1.8.0_92 which is pretty ancient.
So there is a clear mismatch between the JDK v8u92 and current Selenium Client v3.14.0.
Solution
- Upgrade JDK to recent levels JDK 8u181.
- Upgrade Selenium to current levels Version 3.14.0.
- Upgrade ChromeDriver to current ChromeDriver v2.41 level.
- Keep Chrome version between Chrome v66-68 levels. (as per ChromeDriver v2.41 release notes)
- Take a System Reboot.
- Execute your
@Test
.
Exception in thread main org.openqa.selenium.WebDriverException: unknown error: unexpected command response using Selenium Java
To click on the element No thanks instead of visibilityOfElementLocated() you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following locator strategy:
Using id:
new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.id("birtviewer"))).click();
Using cssSelector:
new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.cssSelector("button#wzrk-cancel"))).click();
Using xpath:
new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@id='wzrk-cancel']"))).click();
Related Topics
Linking a C Library and Its Supporting Library in Swift (Linux)
-Bash: /Usr/Bin/Yum: /Usr/Bin/Python: Bad Interpreter: No Such File or Directory
Svn Checkout the Contents of a Folder, Not the Folder Itself
How to Delete First Two Lines and Last Four Lines from a Text File with Bash
How to Get the Nvidia Driver Version from the Command Line
Bash: Let Statement VS Assignment
When Is Clone() and Fork Better Than Pthreads
Does the Linux Filesystem Cache Files Efficiently
Should %Rsp Be Aligned to 16-Byte Boundary Before Calling a Function in Nasm
Deleting String Up to the First Occurrence of Certain Character
Backup a Running Docker Container
How to Display Modified Date Time with 'Find' Command