I've recently started getting into learning selenium and java on its own, been following a course online however keep receiving these two error messages when trying to do so, the code is essentially meant to find the google browser and input the text into the search bar automatically, but it loads up google and does nothing.
Code:
package test;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
public class test1 {
public static void main(String[] args) {
test();
}
public static void test() {
System.getProperty("WebDriver.chrome.driver");
WebDriver driver = new ChromeDriver();
//go to google.com
driver.get("https://www.google.com");
//enter text in search box
driver.findElement(By.name("q")).sendKeys("Automation step by step");
//click on search button
driver.findElement(By.name("btnK")).click();
//close browser
driver.close();`your text`
System.out.println("Test completed");
}
}
Console:
Oct 30, 2024 9:49:24 AM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
WARNING: Unable to find an exact match for CDP version 130, returning the closest version; found: 129; Please update to a Selenium version that supports CDP version 130
Exception in thread "main" org.openqa.selenium.ElementNotInteractableException: element not interactable
What can I do to fix this, as I'm completely new to this and a bit confused by the error
WARNING: Unable to find an exact match for CDP version 130, returning the closest version; found: 129; Please update to a Selenium version that supports CDP version 130
You can ignore the above. It's just a Warning and not and Exception. Basically warning is just about the chromedriver.exe and chrome version mismatch.
Exception in thread "main" org.openqa.selenium.ElementNotInteractableException: element not interactable
Above exception is your real issue. It seems like selenium is not able to interact with the targeted element as some other element is covering the target element. I think in this case it is, Accept/Reject cookies pop-up.
Try getting rid of the pop-up by clicking on Accept all button before you send text to the google search.
Check the code below:
driver.findElement(By.xpath("//div[text()='Accept all']")).click();
//enter text in search box
driver.findElement(By.name("q")).sendKeys("Automation step by step");