如何在selenium控制台中打印html元素

时间:2018-02-07 11:24:45

标签: selenium automation automated-tests

HTML代码: -

< label ng-if="menuItem.titleColor" 
ng-style="{'color':menuItem.titleColor}" style="text-align: center; font-weight: normal; color: rgb(255, 255, 255);" class="ng-binding ng-scope">

Group

< /label>

Selenium代码: -

    String locatorg = "//label";
    By findBytextg = By.xpath(locatorg);
    System.out.print(findBytextg.toString());

如何在Eclipse中的Selenium控制台中打印所有属性?????

1 个答案:

答案 0 :(得分:0)

如果我正确理解您的请求,您希望打印出包含其所有属性的HTML元素。你可以使用&#39; outerHTML&#39;要执行该操作的元素属性。请注意,您首先需要访问该元素。我的Java有点生疏,但你可以试试这个:

String locatorg = "//label";
By findBytextg = By.xpath(locatorg);
webelement labelElement = driver.findElement(findBytextg);
System.out.print(labelElement.getAttribute('outerHTML'));