Reputation: 524
I'm trying to select a value from Dropdown on "www.parcelhero.com" but fail to do so. When I execute the script the page loads and when the dropdown is accessed the controls move down in the page and a dark animation video where the dropdown existed earlier plays. Why script is not able to access the dropdown? Is it because its there on an animation?
WebDriver driver= new FirefoxDriver();
driver.get("https://www.parcelhero.com");
WebElement element=driver.findElement(By.name("Consignor.Address.CountryId"));
Select se=new Select(element);
se.selectByVisibleText("INDIA");
Upvotes: 2
Views: 84
Reputation: 84
My code is working fine with some tricks. Do one thing when browser injects, do not maximize it, But minimize it to the half of the screen(Manually for debugging).
Run this code
WebElement element1=driver.findElement(By.name("Consignor.Address.CountryId"));
Select newselect = new Select(element1);
ArrayList<String> valuesInList = new ArrayList<String>();
for(WebElement element:newselect.getOptions())
{
valuesInList.add(element.getText());
}
newselect.selectByVisibleText("INDIA");
Let me know if it is working for you too.
Upvotes: 0
Reputation: 16201
This is nothing but the wait issue. I just verified and the following code works everytime I run it. Implementing Explicit waits in this kind of scenario is always good idea.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
/**
* @author Saifur
*
*/
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "E:\\working\\selenium\\drivers\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.parcelhero.com/");
WebElement element = new WebDriverWait(driver, 10)
.until(ExpectedConditions.visibilityOfElementLocated(By.name("Consignor.Address.CountryId")));
Select se = new Select(element);
se.selectByVisibleText("INDIA");
}
}
Upvotes: 2