package com.project.Amazon.com;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.PageFactory;
public class AmazonTest {
public static void main(String[] args) throws InterruptedException {
try{
// Create a new instance of a driver
System.setProperty("webdriver.chrome.driver", "F:/SeleniumRepository/SeleniumBrowserjars/chromedriver.exe");
WebDriver driver = new ChromeDriver();
// Navigate to the right place
driver.get("https://www.amazon.ca/");
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.manage().window().maximize();
AmazonSearch page = PageFactory.initElements(driver,AmazonSearch.class);
page.drop.selectByValue("Books");
page.sendText("Pirates of caribbean");
}
package com.project.Amazon.com;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.Select;
public class AmazonSearch {
private WebDriver driver;
// The element is now looked up using the name attribute
public AmazonSearch(WebDriver driver){
this.driver = driver;
PageFactory.initElements(driver, this);
}
@FindBy(how=How.CSS,using="#searchDropdownBox")
private WebElement dropselect;
@FindBy(how=How.ID,using ="twotabsearchtextbox")
private WebElement Searchbox;
@FindBy(how=How.CLASS_NAME,using="nav-input")
private WebElement SearchButton;
Select drop =new Select(dropselect);
public void sendText(String text){
Searchbox.sendKeys(text);
System.out.println(text);
SearchButton.click();
}
}
Kindly Let me know what causing this exception. I', trying to automate Amazon search page using page factory and facing the issue