C# Appium Android Errors inteacting with Locators

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.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> 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);
</code>
<code> 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); </code>
    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.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> 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));
}
</code>
<code> 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)); } </code>
        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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> 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"); }
}
</code>
<code> 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"); } } </code>
     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"); }
    }

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật