I'm trying to run the following code but i keep getting a null pointer on the Select element ...
Here is the example of my code I use:
@FindBy(id="ddCompany")
WebElement Select;
public void Test(){
driver.findElement(By.id("igtxtdfUsername")).sendKeys("dimitri");
Select dropdown = new Select(Select);
dropdown.getOptions().get(1).click();
driver.findElement(By.id("igtxtdfPassword")).sendKeys("dimitri");
driver.findElement(By.id("Login")).click();
driver.quit();
We can't use the Driver.findElement function so we have to find a way to work arround with the Find By .. I putted a sout after the dropdown but it just gave me Null.
You can always use xpath to locate the select element if you don't have className, id or name. you're getting an exception because the constructor for select is expecting a not null WebElement
https://code.google.com/p/selenium/source/browse/java/client/src/org/openqa/selenium/support/ui/Select.java
First of all select class has constructor like :
Select(WebElement element)
So if you do like below , it should work :
@FindBy(id="ddCompany")
private WebElement Select;
Select dropdown = new Select(Select);
dropdown.getOptions().get(1).click();
Make sure your ID for find element is correct.
You can check more about Select mechanism here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With