- m_finn
- Posts : 1
Join date : 2017-06-06
If element exists/wait for when using PageFactory with C#
Tue Jun 06, 2017 1:18 am
Hi,
I need to click an okay button which might appear after completing a field - it might take 5 seconds to appear. So i need IF Wait for existence 5 seconds. I'm using C# PageFactory as well.
Not sure how to do the If element exists, i could just put a 5 second sleep before the IF statement button but I wondered if there was a better way to check for both?
TIA
I need to click an okay button which might appear after completing a field - it might take 5 seconds to appear. So i need IF Wait for existence 5 seconds. I'm using C# PageFactory as well.
- Code:
FindsBy(How = How.Name, Using = "OK")]
private IWebElement alertOKBtn;
public void PopulateFields //method to populate the form
{
// Populate fields
dateFromField.SendKeys(DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"));
// Click on this field
descriptionField.Click();
//OK button might appear, might take 5secs - pseudcode
if ( alertOKBtn exists, wait for it for 5 secs.. )
{
alertOkBtn.Click();
}
//continue populating form
}
Not sure how to do the If element exists, i could just put a 5 second sleep before the IF statement button but I wondered if there was a better way to check for both?
TIA
Permissions in this forum:
You cannot reply to topics in this forum