find elements Test NUnit Visual Studio 2022

This commit is contained in:
Lukáš Kaňka 2023-08-23 12:35:57 +02:00
parent ca94d2f795
commit 410c9c9dbc
22 changed files with 67 additions and 3 deletions

View File

@ -0,0 +1,51 @@
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SeleniumNunitProject.Tests
{
internal class FindElementTest
{
[Test]
public void LocatorsTest()
{
var results = new List<string>();
IWebDriver driver = new FirefoxDriver();
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl("https://www.selenium.dev/");
Assert.That(driver.Title, Is.EqualTo("Selenium"));
// h2 element mánastránce více prvků oproti h1
// FindElement --> načte první h2 v seznamuna stránce
var firstH2 = driver.FindElement(By.XPath("//h2"));
results.Add($"FindElement: {firstH2.Text}");
// FindElements --> vrátí všechny elementy h2 na stránce
var h2Collection = driver.FindElements(By.XPath("//h2"));
foreach ( var h2 in h2Collection )
{
results.Add($"FindsElements: {h2.Text}");
}
// evaluate a subset of the DOM
var parentElement = driver.FindElement(By.CssSelector("div[id='main_navbar']"));
var links = parentElement.FindElements(By.TagName("a"));
foreach ( var link in links )
{
var result = link.Text;
if (!string.IsNullOrEmpty(result))
{
results.Add($"links: {link.Text}");
}
}
File.WriteAllLines("results", results);
driver.Quit();
}
}
}

View File

@ -49,7 +49,7 @@ namespace SeleniumNunitProject.Tests
// xpath (text na hlavní straně h1) // xpath (text na hlavní straně h1)
var xpathVAlidator = driver.FindElement(By.XPath("//h1")).Displayed; var xpathVAlidator = driver.FindElement(By.XPath("//h1")).Displayed;
Assert.That(xpathVAlidator, Is.EqualTo(true)); Assert.That(xpathVAlidator, Is.EqualTo(true));
Console.WriteLine(xpathVAlidator);
driver.Quit(); driver.Quit();

View File

@ -0,0 +1,13 @@
FindElement: Getting Started
FindsElements: Getting Started
FindsElements: Selenium Level Sponsors
FindsElements: News
FindsElements: Support the Selenium Project
FindsElements: Donate to Selenium
links: About
links: Downloads
links: Documentation
links: Projects
links: Support
links: Blog
links: English

View File

@ -1 +1 @@
01e6d31dbbd36b9b44f8740f275982f004b85ddc 4ad791b70820c50a5fd253c54ea166f7eb25c24e