How to Process Java Script Executor in Selenium Test Automation | Devstringx Technologies

How to get started with Query Scripts?

package tests;import org.openqa.selenium.JavascriptExecutor;import org.openqa.selenium.WebDriver;import org.openqa.selenium.chrome.ChromeDriver;import org.openqa.selenium.remote.RemoteWebDriver;
public class QueryScriptsTest {
public static void main(String[] args) {System.setProperty(“webdriver.chrome.driver”, “./drivers/chromedriver.exe”);WebDriver driver=new ChromeDriver();driver.manage().window().maximize();driver.get(“https://www.google.com");JavascriptExecutor js = (JavascriptExecutor)driver;//send textString sendAmazonText=”document.querySelector(\”input[title=’Search’]\”).value=\”Amazon\”;”;js.executeScript(sendAmazonText);String clickSearchBtn =”document.querySelectorAll(\”input[value=’Google Search’]\”)[1].click()”;//click buttonjs.executeScript(clickSearchBtn);}}

Devstringx Technologies is highly recommended IT company for custom software development, mobile app development and automation testing services