1

Whenever I am trying to use a list element, this error is showing

Type mismatch: cannot convert from WebElement to List<WebElement>

in appium. Please help!

List <WebElement>a=driver.findElement(By.className("android.widget.EditText"));
3
  • use findElements() method when you're trying to find a list of elements or more than one elements. It may be due to this. Commented Aug 17, 2015 at 2:34
  • Glad it worked after imorting the library .
    – shrey
    Commented Aug 17, 2015 at 2:48
  • Voting to leave open. This is a type of question that I would have come to SQA looking for an answer for when I first started with automation. Commented Jan 27, 2016 at 18:08

2 Answers 2

3

Just replace the findElement () method with findElement**s**(plural).

Since the findElement method always returns a WebElement instead of a List of WebElements. The findElements method will return the list of webelements, which can be referred by a variable of type List<Webelement>.

So the line of code will looks like,..

List<WebElement> a=driver.findElements(By.className("android.widget.EditText"));

Done.

0

You are using findElement method which will return single element but you are try to save it in the list.

Your code should be

 WebElement a=driver.findElement(By.className("android.widget.EditText"));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.