public void Main() { string url = "http://testing.todvachev.com/selectors/css-path/"; //string cssPath = "html.js body#mh-mobile.single.single-post.postid-108.single-format-standard.custom-background.mh-right-sb div.mh-container.mh-container-outer div.mh-wrapper.clearfix div#main-content.mh-content article#post-108.post-108.post.type-post.status-publish.format-standard.has-post-thumbnail.hentry.category-selectors div.entry-content.clearfix figure.entry-thumbnail img"; //string xPath = "/html/body/div/div[2]/div/article/div/figure/img"; // Broken Element - Exception handling string cssPath = "htl.js body#mh-mobile.single.single-post.postid-108.single-format-standard.custom-background.mh-right-sb div.mh-container.mh-container-outer div.mh-wrapper.clearfix div#main-content.mh-content article#post-108.post-108.post.type-post.status-publish.format-standard.has-post-thumbnail.hentry.category-selectors div.entry-content.clearfix figure.entry-thumbnail img"; string xPath = "/htl/body/div/div[2]/div/article/div/fig/img"; IWebDriver driver = new ChromeDriver(); driver.Navigate().GoToUrl(url); IWebElement cssPathElement; IWebElement xPathElement; try { cssPathElement = driver.FindElement(By.CssSelector(cssPath)); xPathElement = driver.FindElement(By.XPath(xPath)); if (cssPathElement.Displayed) { GreenMessage msg = new GreenMessage("I can see the CSS path Element!"); } } catch (NoSuchElementException) { RedMessage msg = new RedMessage("something went wrong with CSS Path element"); } try { xPathElement = driver.FindElement(By.XPath(xPath)); if (xPathElement.Displayed) { GreenMessage msg2 = new GreenMessage("I can see the Xpath Element!"); } } catch (NoSuchElementException) { RedMessage msg2 = new RedMessage("something went wrong with XPath element"); } Thread.Sleep(2000); driver.Quit(); Console.ReadLine(); }
public void Main() { IWebDriver driver = new ChromeDriver(); driver.Navigate().GoToUrl("http://testing.todorvachev.com/selectors/name"); IWebElement element = driver.FindElement(By.Name("myName")); if (element.Displayed) { GreenMessage msg = new GreenMessage("Yes I can see the element!"); } else { RedMessage msg = new RedMessage("Somethign went wrong, couldnt see the element!"); } driver.Quit(); Console.ReadLine(); }
public void Main() { string url = "http://testing.todvachev.com/special-elements/radio-button-test/"; string option = "1"; driver.Navigate().GoToUrl(url); radioButton = driver.FindElement(By.CssSelector(".entry-content > form:nth-child(2) > p:nth-child(6) > input:nth-child(1)")); if (radioButton.GetAttribute("checked") == "true") { GreenMessage msg = new GreenMessage("The radio button is checked!"); } else { RedMessage msg = new RedMessage("This radio button is unchecked!"); } driver.Quit(); Console.ReadLine(); }
public void Main() { string url = "http://testing.todorvachev.com/selectors/id/"; string ID = "testImage"; IWebDriver driver = new ChromeDriver(); driver.Navigate().GoToUrl(url); IWebElement element = driver.FindElement(By.Id(ID)); if (element.Displayed) { GreenMessage msg = new GreenMessage("Yes, I can see it!"); } else { RedMessage msg = new RedMessage("Nope, it is not there"); } Thread.Sleep(2000); driver.Quit(); Console.ReadLine(); }