简体   繁体   中英

C# Selenium copy text

<td style="padding:10px;color:#565a5c;font-size:32px;font-weight:500;text-align:center;padding-bottom:25px;">836712</td>

I want to copy the number "836712" above but have no idea how to do it. Please help me. The above codes are taken from a site. I want to copy using C# selenium.

plss

use the getText() function on the WebElement. Since you only pasted the td element i can't know the hierarchy of the html. Focus on a parent with an ID (that renders it unique) then using JS cycle trough its children for n times where n is the number of the td element you're searching for from parent. Then use getText() on it.

take a look here

Code snippet (to convert from Java):

        String code = "";

        yourWebElementsArray = driver.findElements(By.tagName("td"));
    
        for(WebElement el: yourWebelementsArray) {
    
    if(el.getAttribute("color").equals("#565a5c") && el.getAttribute("font-size").equals("32px")) {

  code = el.getText();

}

}

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