3 回答

TA貢獻1796條經驗 獲得超4個贊
長短不一:除非您想使用“JavascriptExecutor”,否則沒有一種使用簡單的 Selenium 函數獲取文本值的簡潔方法
另一種選擇是<td>使用簡單的硒操作從元素中獲取整個文本,然后使用 String 函數substring()獲取您的應用程序編號值,該值卡在引號之間"。
代碼:
String input = driver.findElement(By.xpath("//table[@class='table table-hover']/tbody/tr/td")).getAttribute("innerText");
input = input.substring(input.indexOf("\"")+1, input.lastIndexOf("\""));
System.out.println("Extracted Value" + input);

TA貢獻1828條經驗 獲得超13個贊
根據您共享的HTML提取數字,即3204255,您需要誘導WebDriverWait以使所需元素可見,然后您可以executeScript()按照以下解決方案使用該方法:
Java解決方案:
WebElement myElement = new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//table[@class='table table-hover']//tbody/tr/td")));
String myText = ((JavascriptExecutor)driver).executeScript('return arguments[0].childNodes[2].textContent;', myElement).toString();

TA貢獻1796條經驗 獲得超7個贊
text: 3204247 不包含在 div 標簽中,而是包含在<td>. 你可以試試這個:
webElement webelement=driver.findElement(By.xpath("//table[@class='table table-hover']/tbody/tr/td"));// you can improve this locator and can also use one below
//webElement webelement=driver.findElement(By.xpath("//div[@class='responsive-show']/..")); using xpath axes
String value=webelement.getText();// OR
//String value=webelement.getAttribute("innerText");
添加回答
舉報