mardi 14 mars 2017

Get text of random element from an array using C# (Selenium)

This is a method for my Selenium page object (the page is referred to here as "LandingPage_Page") - this method is meant to get the text of 1 element, but the trick is, that element is chosen randomly from a page that contains 12 similar elements. I want it to grab a different element from those 12 each time the test runs.

    public LandingPage_Page ArticleThumbnailTitle()
    {
        Random r = new Random();
        int rInt = r.Next(0, 11);

        var articleThumbTitle = Driver.FindElements(By.CssSelector(".row .article-title"));
        articleThumbTitle = articleThumbTitle[rInt].Text();            

        return this; 

.Text() is giving me a error, it's saying: "Non-invocable member 'IWebElement.Text' cannot be used like a method." -- Is articleThumbTitle an array? I want it to be... If so, am I calling the random number into the array correctly?

Thanks in advance for any guidance, Y.




Aucun commentaire:

Enregistrer un commentaire