How can I get values from Selenium WebElement more than faster?

前端 未结 1 1280
梦如初夏
梦如初夏 2021-01-16 05:33

This is my test code to get value from Selenium WebElement.

import java.util.List;    
import org.apache.commons.lang3.ObjectUtils.Null;
import org.openqa.se         


        
相关标签:
1条回答
  • 2021-01-16 06:07

    You can using Javascript, code below will return an ArrayList of Map with tag name, id, href, class keys almost instantly:

    ArrayList<Maps> list = (ArrayList) ((JavascriptExecutor) driver).executeScript("return [...document.querySelectorAll(\"*\")].map(e=>{return {tagName:(e.tagName==undefined?null:e.tagName),class:(e.className==undefined?null:e.className),id:(e.id==undefined?null:e.id),href:(e.href==undefined?null:e.href)}})");
    

    All you need is to add js code to get location and size. For text you can use textContent.
    Before execute the script be sure page is loaded.

    0 讨论(0)
提交回复
热议问题