Created
September 28, 2020 13:38
-
-
Save muditlambda/8f6ab0e0a8f6d772ce407c3d0855aee9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static org.testng.Assert.assertEquals; | |
import org.openqa.selenium.By; | |
import org.openqa.selenium.Keys; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.WebElement; | |
import org.openqa.selenium.chrome.ChromeDriver; | |
import org.openqa.selenium.interactions.Actions; | |
public class click { | |
public static void main(String[] args) { | |
//specify the driver location | |
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Shalini\\Downloads\\Driver\\chromedriver.exe"); | |
//instantiate the driver | |
WebDriver driver = new ChromeDriver(); | |
//specify the URL of the webpage | |
driver.get("https://www.amazon.in/"); | |
//maximise the window | |
driver.manage().window().maximize(); | |
//create an object for the Actions class and pass the driver argument | |
Actions action = new Actions(driver); | |
//specify the locator of the search box in which the product has to be typed | |
WebElement elementToType = driver.findElement(By.id("twotabsearchtextbox")); | |
//pass the value of the product | |
action.sendKeys(elementToType, "iphone").build().perform(); | |
//specify the locator of the search button | |
WebElement elementToClick = driver.findElement(By.className("nav-input")); | |
//perform a mouse click on the search button | |
action.click(elementToClick).build().perform(); | |
//verify the title of the website after searching the product | |
assertEquals(driver.getTitle(), "Amazon.in : iphone"); | |
driver.quit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment