3

I was just playing around automating gmail website using Selenium with Java and I was stuck at the language selection drop down in gmail home page. After selecting the dropdown, I am not able to select any specific language from the listbox as I am getting element not visible exception. How can we select elements from such list boxes? I have already tried using many general techniques like Actions, explicit wait etc.

sri999
  • 31
  • 2
  • This happens when I use a web component drop down with Polymer, I can see the dropdown element tags in the dev tools that come with the browser, but it seems that Selenium is having trouble because every time you click the dropdown menu, the focus gets reset and selenium is refocused on the

    tag. Would love to have someone answer this question

    – Harvey Lin Apr 03 '18 at 06:15

2 Answers2

0

After login the following code will, as an example, select language Dansk. Important here is to use the Selenium Select class. For documentation see: https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/support/ui/Select.html

    WebDriverWait wait = new WebDriverWait(driver, 15);
    WebElement next = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//content/span[contains(text(),'Next')]")));
    next.click();
    WebElement settings = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[contains(@class,'aos T-I-J3 J-J5-Ji')]")));
    settings.click();
    WebElement settingsmenuchoice = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[contains(@class,'J-N aMS')]")));
    settingsmenuchoice.click();
    WebElement select = wait.until(ExpectedConditions.elementToBeClickable(By.id(":m4")));
    select.click();
    Select languageDropdown = new Select(select);
    List<WebElement> Options = languageDropdown.getOptions();
    for(WebElement option:Options){
        if(option.getText().equals("Dansk")) {
          option.click();      
        }               
    }
Frank
  • 831
  • 1
  • 11
  • 23
0

I tried to do the same as you, I succeed by changing the language but also I couldn't choose the language I want. here is the method I used:

driver.findElement(By.xpath("//div[@class='u7land']")).click();
driver.findElement(By.xpath("//div[@class='ry3kXd Ulgu9']")).click();
driver.findElement(By.xpath("//div[@class='OA0qNb ncFHed']")).click();
Phoenix
  • 3,996
  • 4
  • 29
  • 40