Вы находитесь на странице: 1из 2

1)How to count the number of rows in webtable. Simple approach.?

--- Count row


@Test
public void count_row(){
WebDriver driver = new FirefoxDriver();
driver.get("C:\\Users\\ARKA\\Desktop\\tble.html");
List <WebElement> rc = driver.findElements(By.cssSelector(".mytable tr"));
System.out.print("The no of rows : "+ rc.size());
}
2) How to find the dynamic elements on the web page. Value of the element keep on changing?
HTML FORMAT OF TABLE___________<table style="width:100%" class="mytable">
<tr id="my_1">
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr id="my_2">
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr id="my_3">
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
</tr>
</table>

for this type of dynamic id (See the tr)


------------------------------------------------List <WebElement> rc1 = driver.findElements(By.cssSelector("[id^=my]"));
System.out.print("The no of rows id starts with my : "+ rc1.size());

Mohit Puri We are using regular expression in above code


Like Reply 20 hrs
Mohit Puri [id^=my]

3)We have scenario leta say there are two links with same property and value and I want to click on
second element how can I do?

List <WebElement> rc3 = driver.findElements(By.cssSelector("a"));


int count = 0;
for(WebElement a : rc3){
if(count==1){
a.click();
}
count++;
}
4)
hi everyone
one interview question is
in your project which part of your programme u use overloading then what we explain....?
ans) driver.switchTo().frame(2);
driver.switchTo().frame("name_of_frame");........this is overloading

Вам также может понравиться