Grab a drink, this may get long.
I am building out an appium test env. I have the inspector, android sdk and appium up and running. I am seeing errors trying to interact with android page objects. They are found but I can’t interact with them. I am trying to use an existing selenium/specflow framework so I can reuse the same methods. This could be the problem?
I ran into a lot of posts regarding appium and selenium 4 so I dropped down to selenium 3 for this solution.
Anyone see what I am missing here?
Invoking the driver. I use _webdriver for chrome/edge. As mentioned, I am trying to keep this so I can use existing methods I have in place like IsElementPresent, Waits etc.
public class Browser
{
static IWebDriver _webDriver;
static WebDriverWait _wait;
var appiumOptions = new AppiumOptions();
appiumOptions.AddAdditionalCapability("platformName", "Android");
appiumOptions.AddAdditionalCapability("deviceName", "Pixel 8 Pro");
appiumOptions.AddAdditionalCapability("appium:automationName", "UiAutomator2");
appiumOptions.AddAdditionalCapability("appPackage", "com.android.settings");
appiumOptions.AddAdditionalCapability("appActivity", ".Settings");
appiumOptions.AddAdditionalCapability("noReset", true);
_webDriver = new AndroidDriver<IWebElement>(new Uri("http://127.0.0.1:4723/"), appiumOptions);
_webDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(30);
}
In my step I can try this. The bool returns true.
bool ele1 = Browser.IsElementPresent_byId("com.android.chrome:id/search_box_text");
if (ele1)
{ Browser.FindElement_byId("com.android.chrome:id/search_box_text").SendKeys("123");
}
public static IWebElement FindElement_byId(string element)
{
WaitForElementDisplayed_byId(element);
return _webDriver.FindElement(By.Id(element));
}
WaitForElementDisplayed_byId(element)
This throws error System.NullReferenceException: ‘Object reference not set to an instance of an object.’
If I comment WaitForElementDisplayed_byId out since I know the element exists I get:
OpenQA.Selenium.NoSuchElementException: ‘An element could not be located on the page using the given search parameters.’
WaitForElementDisplayed_byId Method:
public static void WaitForElementDisplayed_byId(string elementName)
{
try { _wait.Until(webDriver => webDriver.FindElement(By.Id(elementName)).Displayed); }
catch (StaleElementReferenceException) { WaitForElementDisplayed_byId(elementName); }
catch (NoSuchElementException) { WaitForElementDisplayed_byId(elementName); }
catch (WebDriverTimeoutException) { TakeScreenshot("timeoutById"); }
}