findElement method

Hello,

I am trying to use findElements method with a drop down.

I use the following line:

Select oSdropDown = new Select((WebElement)driver.findElements(By.id(“continents”)));

IĀ  have some more code below. If I use findElements, the code below is no longer executed, but if I use findElement it does. As I have read, findElements method returns all the elements to be found or only one if it is the case.

So does anybody know why the above situation?

 

Thanks! šŸ™‚

Add Comment
  • 1 Answer(s)

    I have found my answer for the above.

    It seems that using the findElements method must be accompanied by explicitly use of get() method to fetch the first element.

    So in this case, the above command will transform into:Ā  Select oSdropDown = new Select((WebElement)driver.findElements(By.id(“continents”)).get(0)); šŸ™‚

    Default Answered on July 16, 2018.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.