我想在控制台上打印我的元素
WebElement element = driver.findElement(
By.xpath("//*[name()='svg']/*[name()='rect' and @height='40']")
);
String val = element.getText();
System.out.println("val");
答案 0 :(得分:0)
可能有多个问题,例如
以下代码正在工作,并从表中打印大约50个值,即公司名称和平均工资
public void naukriTest() throws InterruptedException{
driver.get("https://www.naukri.com/nlogin/login");
driver.findElement(By.id("usernameField")).sendKeys("validemail");
driver.findElement(By.id("passwordField")).sendKeys("validpassword");
driver.findElement(By.xpath("//button[@class='waves-effect waves-light btn-large btn-block btn-bold blue-btn']")).click();
Thread.sleep(3000);
driver.get("https://careernavigator.naukri.com/sales-executive-retail-careers-in-mahindra-and-mahindra-financial-services-15731");
Thread.sleep(18000);
System.out.println(driver.getTitle());
List<WebElement> simpleTable = driver.findElements(By.xpath("(//*[name()='svg'])[2]//*[name()='text']//*[name()='tspan' and (@dy='4.40625' or @dy='3.609375')]"));
System.out.println("size is " + simpleTable.size());
for (int i=0;i<simpleTable.size();i++)
System.out.println(simpleTable.get(i).getText());
}
请不要将-ve标记为thread.sleep,因为我只是专注于找到正确的xpath并从DOM中打印值。