-
Notifications
You must be signed in to change notification settings - Fork 0
Overview
Arman edited this page Aug 26, 2022
·
3 revisions
Welcome to the SeleniumChains wiki!
SeleniumChains is a library for fluent use and Avoiding repetitive code. This library has many helpful extension methods.
Usage: The first step must be to create a WebDriver:
IWebDriver driver = new FirefoxDriver();
string webUrl = "https://www.wikipedia.org/";
After that, now we can use SeleniumChains like that:
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using SeleniumChain;
IWebDriver driver = new FirefoxDriver();
string webUrl = "https://www.wikipedia.org/";
new ChainSelenium().SetDriver(driver)
.ImplicitWaitingForEachPageToLoad(TimeSpan.FromSeconds(3))
.Goto(webUrl)
.PageScrollDown()
.ClickOnElement(config => config
.ClickOnElementById("searchLanguage")
.ClickOnElementByCssSelector("#searchLanguage > option:nth-child(21)")
)
.WriteInElement(config => config
.WriteInElementById("searchInput", "کوروش")
.WriteAppendInElementById(" بزرگ")
.WritePrependInElementById("پادشاه " + Keys.Enter))
.ClickOnElement(config => config
.ClickOnElementByLinkText("کوروش بزرگ"))
.ClickOnElement(config => config
.ClickOnElementById("p-lang-btn")
.ClickOnElementByXPath("/html/body/div[1]/div[2]/div[1]/div/ul[2]/li[3]/a")
)
.PageScrollDown()
.ClickOnElement(config => config
.ClickOnElementByCssSelector("#mw-normal-catlinks > ul:nth-child(2) > li:nth-child(1) > a:nth-child(1)")
)
.WriteInElement(config => config
.WriteInElementById("searchInput", "ljklkjfdfdjkfasdfl")
.ClearTextInputElementById()
.WriteInElementById("Order of Assassins" + Keys.Enter)
)
.ClickOnElement(config => config
.ClickOnElementByXPath("/html/body/div[3]/div[3]/div[5]/div[1]/div[4]/ul/li[5]/a"))
.ClickOnElementById("p-logo")
.ClickOnElementById("ca-viewsource")
.ScrollDownElementIfExistsById("wpTextbox1")
;
Note: If you want to do multiple tasks on an element, you can do it in 2 ways:
The first way is to repeat the Locator on each command:
.WriteInElement(config => config
.WriteInElementById("searchInput", "کوروش")
.WriteAppendInElementById("searchInput"," بزرگ")
.WritePrependInElementById("searchInput","پادشاه " + Keys.Enter))
As you can see in the code above, "searchInput" is repeated in all three commands.
Or
You can set the Locator For the first command, and there is no need to select the locator for the following orders.:
.WriteInElement(config => config
.WriteInElementById("searchInput", "کوروش")
.WriteAppendInElementById(" بزرگ")
.WritePrependInElementById("پادشاه " + Keys.Enter))