package Roughpack;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
public class MyClass {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver","D:\\Executabel\\geckodriver-v0.21.0-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
WebDriverWait wait = new WebDriverWait(driver, 20);
driver.get("http://pro.tykitksa.com/");
driver.manage().window().maximize();
driver.manage().timeouts().pageLoadTimeout(5, TimeUnit.SECONDS);
List<WebElement> dropDownList = driver.findElements(By.id("user_event_city"));
System.out.println(dropDownList.size());
for (int i = 0; i < dropDownList.size(); i++) {
System.out.println(dropDownList.get(i).getText());
WebElement Dropdown = driver.findElement(By.id("user_event_city"));
Select select = new Select(Dropdown);
select.selectByIndex(4);
}
}
}
Asked
Active
Viewed 5,162 times
1
1 Answers
1
You need to add wait for cityModal webelement, because on page load your dropdown is nit visible:
System.setProperty("webdriver.gecko.driver","D:\\Executabel\\geckodriver-v0.21.0-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
WebDriverWait wait = new WebDriverWait(driver, 20);
driver.get("http://pro.tykitksa.com/");
driver.manage().window().maximize();
driver.manage().timeouts().pageLoadTimeout(5, TimeUnit.SECONDS);
//this is wait for se-pre-con-home element will be invisible
wait.until(ExpectedConditions.invisibilityOf(driver.findElement(By.xpath("//div[@class=\"se-pre-con-home\"]"))));
List<WebElement> dropDownList = driver.findElements(By.id("user_event_city"));
System.out.println(dropDownList.size());
for (int i = 0; i < dropDownList.size(); i++) {
System.out.println(dropDownList.get(i).getText());
WebElement Dropdown = driver.findElement(By.id("user_event_city"));
Select select = new Select(Dropdown);
select.selectByIndex(4);

Sergiy Konoplyaniy
- 388
- 3
- 10
-
But all the dropdown list is shown on the console System.out.println(dropDownList.get(i).getText()); – Sanddy Jul 11 '18 at 09:52
-
it's in your browser when page is already opened, but when you start webdriver your page looks like https://prnt.sc/k53yg8 then like https://prnt.sc/k53yje -> https://prnt.sc/k53yje, so you need to wait for cityModal element – Sergiy Konoplyaniy Jul 11 '18 at 09:58
-
Got the same exception Exception in thread "main" org.openqa.selenium.ElementClickInterceptedException: Element – Sanddy Jul 11 '18 at 09:59
-
@MyTesting_Account look now to solution and try again please, I edit wait – Sergiy Konoplyaniy Jul 11 '18 at 10:18
-
@ Sergiy Konoplyaniy Thanks mate Now its work fine.... – Sanddy Jul 11 '18 at 10:25
-
great, if so please accept my answer – Sergiy Konoplyaniy Jul 11 '18 at 10:26