Created
April 24, 2020 15:49
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Search Page Object (Src\PageObject\Pages\SearchPage.cs) | |
using System; | |
using OpenQA.Selenium; | |
using OpenQA.Selenium.Remote; | |
using NUnit.Framework; | |
using System.Threading; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using OpenQA.Selenium.Support.UI; | |
// For supporting Page Object Model | |
// Obsolete - using OpenQA.Selenium.Support.PageObjects; | |
using SeleniumExtras.PageObjects; | |
namespace POMExample.PageObjects | |
{ | |
class SearchPage | |
{ | |
private IWebDriver driver; | |
Int32 timeout = 10000; // in milliseconds | |
public SearchPage(IWebDriver driver) | |
{ | |
this.driver = driver; | |
PageFactory.InitElements(driver, this); | |
} | |
[FindsBy(How = How.XPath, Using = "//*[@id='rso']/div[1]/div/div/div/div/div[1]/a/h3")] | |
private IWebElement elem_first_result; | |
async void async_delay() | |
{ | |
await Task.Delay(50); | |
} | |
public FinalPage click_search_results() | |
{ | |
var wait = new WebDriverWait(driver, TimeSpan.FromMilliseconds(timeout)); | |
// Wait for the page to load | |
wait.Until(d => ((IJavaScriptExecutor)d).ExecuteScript("return document.readyState").Equals("complete")); | |
elem_first_result.Click(); | |
async_delay(); | |
return new FinalPage(driver); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment