-1

Error CS0029 Can not implicitly convert type OpenQA.Selenium.IWebElement em string

What I am doing is:

// Declaration of the global variable portalweb
public string portalweb;

// function to click on button
public void btnCcnpj_Click_1(object sender, EventArgs e) {
    IWebDriver driver = new ChromeDriver();

    driver.Navigate().GoToUrl("http://...");

    IWebElement secondRow = driver.FindElement(By.CssSelector("tr:nth-of-type(2)"));
    IWebElement client = secondRow.FindElement(By.CssSelector("td:nth-of-type(3)"));
    IWebElement portal = secondRow.FindElement(By.CssSelector("td:nth-of-type(4) a"));
    IWebElement nomeDoPortal = secondRow.FindElement(By.CssSelector("td:nth-of-type(5)"));

    portalweb = portal;
}

// TextBox where the HTML data should appear (in this example the number: 1149)
private void txbPortal_TextChanged(object sender, EventArgs e)
{
    txbPortal.Text = portalweb;
}
3

A web element can have many attributes. You're using one of it's attributes to find it (it's class). It can also have an ID, a href, a value, any number of attributes depending on the type of web element. Your portal element seems to be an anchor (a). An anchors text attribute is a string. So if you getText() of this element you should have what you're looking for.

| improve this answer | |
  • I can not put my code together, could you help me? I'm a beginner and I do not know much yet. – Ronison Matos Jan 9 '19 at 13:53
  • Here is my HTML code: sqa.stackexchange.com/questions/37202/… – Ronison Matos Jan 9 '19 at 13:56
  • 1
    @Ronison Matos you need portalweb = portal.Text; or portalweb = portal.GetAttribute("text"); instead of portalweb = portal. portal is an IWebElement while portalweb is a string, two different types. So you need the text attribute of the IWebElement as that one is a string as well. – Bence Kaulics Jan 9 '19 at 22:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.