What I want to do is: 1- Going to this site: http://www.emlakyonetim.com.tr/tr-TR/sitelerimiz , 2- Click on first dropdown - click a city, click second dropdown - click a county, click third dropdown.
At short, second dropdown items are dependant on first one and third dropdown items are dependant on second one.
Code (not complete):
@Test
public void SiteCek() throws InterruptedException
{
driver.get("http://www.emlakyonetim.com.tr/tr-TR/sitelerimiz");
Thread.sleep(2000);
driver.findElement(By.id("select2-city-list-container")).click();
List<WebElement> elm = driver.findElements(By.xpath("//*[@class='select2-results__option']"));
for(int i = 1; i < elm.size(); i++)
{
By ID = By.id(driver.findElements(By.xpath("//*[@class='select2-results__option']")).get(i).getText());
System.out.println(ID);
driver.findElements(By.xpath("//*[@class='select2-results__option']")).get(i).click();
Thread.sleep(500);
}
}
I get java.lang.IndexOutOfBoundsException: Index: 2, Size: 0 error after city "ADANA". If I manage to handle first error, I will write second and third for loops, so code is this for now.
When the issue is solved I want to get all cities first. Then countys of each city. Then sites of each county. This must be done dynamically as the size of city list, county list and site list. To do that I need three nested for loops. After all of that, each value must be written in excel.