-1

I need a little help. I'm trying to run an automated test on the website http://zara.com and i want to select the language from the language dropdown.

This is the HTML code from Zara. https://prntscr.com/g6hdiv

This is the code i've tried with Selenium 2.53 in IntelliJ

public class RegistrationTest {

 WebDriver driver;

    @Before
    public void setUp(){
        driver = new FirefoxDriver();
        driver.get("http://zara.com");
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    }
    @After
    public void tearDown(){
        driver.quit();
    }

    @Test
    public void test(){

        WebElement languageDropdown = driver.findElement(By.id("language"));
        Select selectLanguage = new Select(languageDropdown);
        selectLanguage.selectByValue("en");
    }

}

I always receive the error below even if I've tried in different setups but it didn't work.

org.openqa.selenium.ElementNotVisibleException: The element is not currently visible and so may not be interacted with

Could you please tell me what am I doing wrong?

Appreciate the help.

SiKing
  • 10,003
  • 10
  • 39
  • 90
Andrei
  • 7
  • 2
  • The error means that the page does not have the dropdown. Can you verify if the dropdown shows up when you execute the test? – Rudrani Angira Aug 09 '17 at 19:42
  • It seems the element is not displayed on the page, as intended by the developer, you should use other means for selecting the language. – lauda Aug 09 '17 at 20:33
  • The dropdown doesn't appear when i run the test. If i try to select different dropdowns on other pages, it works, but with this one it won't . Do you have any idea how should i try ? – Andrei Aug 09 '17 at 21:13
  • Your code does not show you setting the Geckodriver. Did you do that some other way? I just ran your exact code, only using Chrome, and it works just fine. – SiKing Aug 09 '17 at 23:01
  • I just noticed you said: "Selenium 2.53". Is that right? That is seriously outdated! – SiKing Aug 10 '17 at 02:50
  • I'm using Selenium 2.53 so i don't have to set the path for Firefox or Chrome. I've also tried with Chrome but i get the same error :( – Andrei Aug 10 '17 at 06:49
  • If you need the outdated Selenium, you will have to also downgrade your browser to the appropriate version. – SiKing Aug 10 '17 at 15:51
  • I did that, using Firefox 46. Anyway, i found a workaround. I'll have to select the dropdown, then click on it again :( . Thanks for the help anyway. – Andrei Aug 10 '17 at 18:23

1 Answers1

0

The element is not currently visible and so may not be interacted with

You need to scroll the page, so that the element is in the current viewport. Something like this:

WebElement languageDropdown = driver.findElement(By.id("language"));
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", languageDropdown);
Select selectLanguage = new Select(languageDropdown);
selectLanguage.selectByValue("en");
SiKing
  • 10,003
  • 10
  • 39
  • 90
  • Tried the above, but still doesn't work. Same error message. I'm not sure why it's not seeing the element. – Andrei Aug 09 '17 at 22:34