Currently, I am faced with a situation in which I need to locate a WebElement based on its CSS property, specifically the background-color.
I successfully crafted the JQuery script below to pinpoint the element using the firefox console:
$('.search-bar-submit').each(function() {
return $(this).css('background-color') == '#fdd922';
});
https://i.sstatic.net/BjK6i.png
Subsequently, I proceeded to develop the code to accurately identify and click on this WebElement, namely the searchbox:
driver.get("http://www.flipkart.com/");
driver.findElement(By.id("fk-top-search-box")).sendKeys("iphone");
String query = "$('.search-bar-submit').each(function() { "
+ "return $(this).css('background-color') == '#fdd922'; });";
WebElement searchbox = (WebElement) ((JavascriptExecutor)driver).executeScript(query);
searchbox.click();
Upon executing the program, an error
Exception in thread "main" java.lang.NullPointerException
occurs at the line searchbox.click();
If anyone can assist me in finding the searchbox using JavascriptExecutor and then clicking on it, I would greatly appreciate it. Could there possibly be something trivial that I've overlooked?
Your help is highly valued. Thank you in advance.