How to get the value of an attribute using XPath

后端 未结 4 1135
陌清茗
陌清茗 2020-12-10 16:27

I have been testing using Selenium WebDriver and I have been looking for an XPath code to get the value of the attribute of an HTML element as part of my regression testing.

4条回答
  •  Happy的楠姐
    2020-12-10 16:51

    Using C#, .Net 4.5, and Selenium 2.45

    Use findElements to capture firstdiv elements into a collection.

    var firstDivCollection = driver.findElements(By.XPath("//div[@class='firstdiv']"));
    

    Then iterate over the collection.

            foreach (var div in firstDivCollection) {
                div.GetAttribute("alt");
            }
    

提交回复
热议问题