简体   繁体   中英

How does the FindElements.By Make My Code Flow Selenium C#

I have this project that im working on and the part that is making me go insane is where I need to pull data and add it to a textbox (Simple right?)

Let me explain and the show you the code

What it does is, its navigating to a website and then it pulls data from the "tbody tr" (I dont know what its called, I think its called an element)

and then it simply adds it to the textbox.

See, what I dont understand is, is this.

IList<IWebElement> movies = getTopFive.FindElements(By.CssSelector("tbody tr"));

To be more specific.

FindElements(By.CssSelector("tbody tr"));

To be even more specific

FindElements(By.CssSelector());

How do I know what the CssSelector can grab and can not grab, im pretty sure it cant print a picture, thats not its function. I need to understand what its function is and what it is capable of, I did not find any documents online to this, I found it for Java & Python but not for C#

private void label11_Click(object sender, EventArgs e)
{
    var getTopFive = new FirefoxDriver();
    getTopFive.Navigate().GoToUrl("https://www.tradingview.com/");

    IList<IWebElement> movies = getTopFive.FindElements(By.CssSelector("tbody tr"));



    for (int i = 0; i < 1; ++i)
    {
        activeTextBox.Text = movies[i].Text;

    }

}

As the method name -as well as the return type- implies, FindElements() is capable of returning HTML elements . Which element the method would return decided by selector argument it receives. In your particular example, the selector expression is a CSS selector ( By.CssSelector() ) which reads match all tr elements that resides inside tbody element .

For reference : Mozilla Develope Network : Getting started with CSS > Selectors

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM