Selenium Explicit wait for an element in C# with Page Object Model

3,183 views
Skip to first unread message

Ajay

unread,
Apr 22, 2015, 8:26:46 PM4/22/15
to webd...@googlegroups.com

 Hi All,

I was using Page Object Model  with Selenium and Java and I used the below codes to explicitly wait for the element before any action , but I am having trouble implementing the same using C#.

In Java

definition of element  as per Page Object Model:
@FindBy(id="btnLogin")
protected WebElement m_btn;
waiting for the element :
WebDriverWait wait = new WebDriverWait(driver,120);
wait.until(ExpectedConditions.visibilityOf(m_btn));
m_btn.click();

C#
definition of element  as per Page Object Model:
 [FindsBy(How = How.Id, Using = "btnLogin")]
 protected IWebElement m_btn;   
waiting for the element :
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until(ExpectedConditions.ElementIsVisible(m_btn));

 But this giving the below error:

Error The best overloaded method match for 'OpenQA.Selenium.Support.UI.ExpectedConditions.ElementIsVisible(OpenQA.Selenium.By)' has some invalid arguments
and Error Argument 1: cannot convert from 'OpenQA.Selenium.IWebElement' to 'OpenQA.Selenium.By'

I understand that , it need a By locator , but I have already defined the element as per the Object Model.

and I don't want to redefine the elemnt again as in the below code
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
 wait.Until(ExpectedConditions.ElementIsVisible(By.Id("btnLogin")));


How I can accomplish the explicit waiting on the already defined element  without redefining by id again.

Appreciate any help..
Thanks 
Ajay





Øystein

unread,
Apr 23, 2015, 3:29:48 AM4/23/15
to webd...@googlegroups.com

Hi,

 

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));

wait.Until(driver => m_btn.Displayed);

 

//Austin

--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+...@googlegroups.com.
To post to this group, send email to webd...@googlegroups.com.
Visit this group at http://groups.google.com/group/webdriver.
For more options, visit https://groups.google.com/d/optout.

Ajay

unread,
Apr 23, 2015, 9:21:12 AM4/23/15
to webd...@googlegroups.com
Thanks Austin. It worked.

Appreciate your help.
Reply all
Reply to author
Forward
0 new messages