Skip to content

Instantly share code, notes, and snippets.

@ssmiech
Created February 6, 2014 15:43
Show Gist options
  • Save ssmiech/8846686 to your computer and use it in GitHub Desktop.
Save ssmiech/8846686 to your computer and use it in GitHub Desktop.
Clicking <table> column based on another columnt
<table>
<tr>
<th>Name</th>
<th>Mobile</th>
<th>No Introducer</th>
<th>Created On</th>
<th>Status</th>
<th>Action</th>
</tr>
<tr>
<td>Adill</td><td>6666655555</td><td>Nitesh</td><td>05-02-2014</td><td>Pending For Approval</td><td><input>Button</input></td>
</tr>
<tr>
<td>Adill</td><td>6666644444</td><td>Nitesh</td><td>05-02-2014</td><td>Pending For Approval</td><td><input>Button</input></td>
</tr>
<tr>
<td>Adill</td><td>6666633333</td><td>Nitesh</td><td>05-02-2014</td><td>Pending For Approval</td><td><input>Button</input></td>
</tr>
</table>
package selenium;
import java.sql.Driver;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.firefox.FirefoxDriver;;
public class test {
private static WebDriver driver;
public static void main(String[] args) {
driver = new FirefoxDriver();
driver.get("http://localhost");
getRowText();
}
public static String getRowText(){
String text = null;
String column = null;
WebElement table = driver.findElement(By.tagName("table"));
List<WebElement> allrows = table.findElements(By.tagName("tr"));
for(WebElement row : allrows){
List<WebElement> columns = null;
String number = null;
columns = row.findElements(By.tagName("td"));
if (columns.size() > 0) {
number = columns.get(1).getText();
System.out.println(number);
if(number.equals("6666633333")) {
System.out.println("aaaa");
columns.get(5).findElement(By.tagName("input")).click();
}
}
}
return text;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment