我想计算特定文本webdriver java在多个页面上可用的HTML表中的数据
- 我正在尝试计算行的总数李>
我需要统计不同类型的可用状态(非活动、活动、过期和耗尽)
当前代码仅正在获取:
- 行数
- 状态和名称的文本,但我只需要写在状态类型旁边的计数李>
- 它只从第一页获取数据。页面根据事务数填充李>
下面是编写的代码:
import java.util.List; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; public class counting { public static void main(String[] args) { String Status="Inactive"; //String NextPage="Inactive"; WebDriver driver= new FirefoxDriver(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.manage().window().maximize(); driver.navigate().to("http://Testsite/web"); driver.findElement(By.id("UserEntry")).sendKeys("00"); //Type Last Name driver.findElement(By.id("Password")).sendKeys("Test"); // Click on Submit driver.findElement(By.id("LoginButton")).click(); driver.findElement(By.linkText("Accounts")); driver.findElement(By.linkText("Accounts")).click(); driver.findElement(By.xpath("html/body/form/div[3]/div/div[2]/table /tbody/tr/td[1]/div/ul/li[2]/a")).click(); List<WebElement> Account = driver.findElements(By.xpath("//table[@id='MainPlaceholder_AccountList']/tbody/tr/td[1]")); List<WebElement> AccountStatus = driver.findElements(By.xpath("//table[@id='MainPlaceholder_AccountList']/tbody/tr/td[5]")); System.out.println("Total Account- "+Account.size()); System.out.println("Total Status- "+AccountStatus.size());
# 1 楼答案
# 2 楼答案
你的代码没有完全正确格式化。我在移动测试中使用了Appium(所以它是selenium后端),我假设您可以尝试创建一个到达某个点的表,然后创建由某个类名(或者在您的情况下,我假设是一个id值)组成的行
例:
司机是一名司机。这就是我为iOS测试定位某些元素的方式。但我还是要假设逻辑是一样的。一旦你找到了你需要的东西,就用这些对象填充你的数组
一旦你填充了你的数组,你可能会解析它来满足你的需要