Search code examples
selenium-webdriverappium

Selenium webdriver. Help draw up a loop with if else


When I do:

if (driver.FindElementByXPath("//android.widget.RelativeLayout[contains(@resource-id, 'rl_ali_sign_in_btn')]").size()>0)
else {}

I receive:

OpenQA.Selenium.IWebElement "does not contain a definition for the" size "

I need to check the existence of the element and if it exists then do an action


Solution

  • That's because findElementByXPath() doesn't return a List but a WebElement. What you need to use is findElementsByXPath() (elements, not element).