How to perform click using JavascriptExecutor in Selenium?

How to perform click using JavascriptExecutor in Selenium?

The method that I tried is given below. However the result it gives is the below response, java.lang.NullPointerException
At com.sample.testclass.Click(Click.java:25)
At com.run(test.java:21)
Code: driver.findElement(By.id("SearchName")).click();
WebElement elem2 = (new WebDriverWait(driver, 5)). .until(ExpectedConditions.presenceOfElementLocated(By.id("Id1")));
List list = driver.findElements(By.id("Id1"));

for(WebElement web : list). You have two nested 'for' loop in your script and it's very tough to track for each web element's location. You can use the following code snippet to work around the issue.

List list = driver.findElements(By.id("Id1"));
WebElement parent = null;. String id = "";. For (WebElement e : list). System.out.println("inside for");
parent = e;. if (parent.isDisplayed() && parent.getText().

Related Answers

How can we use the Selenium tool with HeadSpin?

Selenium is a tool that is used to automate functional testing. There are two types...

What are 5 Uses of Selenium?

Selenium is a web-automation tool that helps you to test web applications....

How can we use the Selenium tool with HeadSpin?

Selenium is a cross-browser testing automation framework w...