How do I capture text from a web page with Selenium?

Asked

Viewed 1,160 times

1

I need to create a standard People Generator using the site https://www.4devs.com.br/gerador_de_pessoas with Selenium.
That’s the code I have for now:

 [TestFixture]  
 public class GeradorDePessoas
 {
    private IWebDriver driver;

    [SetUp]
    public void SetUp()
    {
        driver = new ChromeDriver();
        driver.Navigate().GoToUrl("https://www.4devs.com.br/gerador_de_pessoas");
    }

    [Test]
    public void DeveGerarUmaPessoa()
    {
        driver.FindElement(By.Name("sexo")).Click();

        SelectElement idade = new SelectElement(driver.FindElement(By.Name("idade")));
        idade.SelectByValue("20");
        driver.FindElement(By.Name("pontuacao")).Click();

        driver.FindElement(By.Id("bt_gerar_pessoa")).Click();


        driver.FindElement(By.XPath("//div[@id='nome']"));
    }

}  

My problem now is that I need to capture the information generated by the site and put it into variables in the program so that they can be called later in other tests. Can anyone help me with that? I have no idea which way to go from now on.

1 answer

0


You can try:

driver.FindElement(By.XPath("//div[@id='nome']")).text;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.