我需要计算可用的不同类型的状态(无效,有效,已过期和已用尽)
当前代码仅提取:
以下是编写的代码:
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());
答案 0 :(得分:0)
您的代码格式不正确。我已经使用Appium(所以它是selenium后端)进行移动测试,我假设您可以尝试创建一个达到某一点的表,然后是由某个className组成的行(或者在我的情况下我假设一个id值)。
前:
table = (MobileElement) driver.findElement(By.xpath("//UIAApplication[1]/UIAWindow[2]/UIATableView[1]"));
rows = table.findElementsByClassName("UIATableCell");
该驱动程序是IOSDriver。现在,这就是我如何找到iOS测试的某些元素。但同样,我将假设逻辑是相同的。找到所需内容后,只需使用对象填充数组即可。
填充阵列后,您可以解析它以满足您的需求。
答案 1 :(得分:0)
for(int i=0;i<AccountStatus.size();i++){
if(AccountStatus.get(i).getText().equals(Status))
System.out.println(Account.get(i).getText()+" --- "+AccountStatus.get(i).getText());
}
}
}
HTML COde:
<table id="MainPlaceholder_AccountList" cellspacing="1" cellpadding="10" border="1" style="background-color:#888888;width:100%;font-size: 75%; padding: 5px;" rules="all">
<tbody>
<tr align="center" style="color:White;background-color:#232356;">
<th scope="col">Account Name</th>
<th scope="col">Number</th>
<th scope="col">Program</th>
<th scope="col">Site</th>
<th scope="col">Status</th>
<th scope="col">Edit</th>
<th scope="col">Delete</th>
</tr>
<tr style="background-color:White;">
<td class="capText" style="width:220px;">Last, First</td>
<td class="padIt" align="center" style="width:60px;">4563201</td>
<td class="capText" style="width:150px;"> </td>
<td class="padIt" style="width:115px;">local</td>
<td class="padIt" style="width:90px;">Active</td>
<td style="width:75px;">
<td style="width:75px;">
<td style="width:75px;">
<input id="MainPlaceholder_AccountList_EditAccount_0" type="submit" style="width:75px;" eid="550" value="Edit..." name="ctl00$MainPlaceholder$AccountList$ctl02$EditAccount">
</td>
<td style="width:75px;">
<input id="MainPlaceholder_AccountList_DeleteAccount_0" type="submit" style="width:75px;" eid="550" onclick="return confirm('Are you sure you want to delete the selected account?');" value="Delete" name="ctl00$MainPlaceholder$AccountList$ctl02$DeleteAccount">
</td>
td style="text-align: center">
<span id="MainPlaceholder_PageLabel" style="margin-right: 5px;">Page:</span>
<input id="MainPlaceholder_CurrentPage" type="text" style="width:40px;text-align: right" onclick="javascript:this.value="";" title="Type in a page number, then press the Enter key to go directly to that page." maxlength="5" value="1" name="ctl00$MainPlaceholder$CurrentPage">
<span id="MainPlaceholder_OfLabel" style="margin-left: 5px; margin-right: 5px;">of</span>
<span id="MainPlaceholder_TotalPages" style="margin-right: 5px;">21</span>
<input id="MainPlaceholder_LastButton" type="submit" style="height:24px;width:90px;" value="▼▼ Last" name="ctl00$MainPlaceholder$LastButton">
<input id="MainPlaceholder_NextButton" type="submit" style="height:24px;width:90px;" value="▼ Next" name="ctl00$MainPlaceholder$NextButton">
<input id="MainPlaceholder_PreviousButton" type="submit" style="height:24px;width:90px;" value="Previous ▲" name="ctl00$MainPlaceholder$PreviousButton">
<input id="MainPlaceholder_FirstButton" type="submit" style="height:24px;width:90px;" value="First ▲▲" name="ctl00$MainPlaceholder$FirstButton">
</td>