Reputation: 235
My task is to Right Click and select one option from the drop down menu for a HTML table.
For this I need help in two things :
How to identify a unique cell inside a table, by using selenium ?
How to Rightclick on the identified cell ?
this application is developed for IE only and sample code of the table is as follows:
table id="ctl00_ContentPlaceHolder1_dgvPatientList" class="grid" cellspacing="0" cellpadding="2" border="1" style="width:96%;border-collapse:collapse;" rules="all">
![this is the code for the HTML table][1] thanks for the help.
Upvotes: 0
Views: 1818
Reputation: 3906
The original question does not specify a language, so this may or may not be applicable, but if you are writing your tests in C# with the .NET version of WebDriver, you can use the TableDriver extension (https://github.com/jkindwall/TableDriver.NET) for locating specific cells in the table.
I have no idea what the contents of table from the original question look like, but to give a generic example, you want to find the cell in the "Price" column from the row where the value in the "Product Id" column is "ABC123", you could use something like this:
Table table = Table.Create(driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_dgvPatientList")));
TableCell cell = table.FindCell("Product Id=ABC123", "Price");
Update
TableDriver.Java is now available. Details here: https://github.com/jkindwall/TableDriver.Java
Upvotes: 0
Reputation: 7339
taking into consideration your first quiestion, it prolly was discussed here (manipultion with table cells using selenium) code provided (in example of code we get text from every cell of the table):
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class WebTableExample
{
public static void main(String[] args)
{
WebDriver driver = new InternetExplorerDriver();
driver.get("http://localhost/test/test.html");
WebElement table_element = driver.findElement(By.id("testTable"));
List<WebElement> tr_collection=table_element.findElements(By.xpath("id('testTable')/tbody/tr"));
System.out.println("NUMBER OF ROWS IN THIS TABLE = "+tr_collection.size());
int row_num,col_num;
row_num=1;
for(WebElement trElement : tr_collection)
{
List<WebElement> td_collection=trElement.findElements(By.xpath("td"));
System.out.println("NUMBER OF COLUMNS="+td_collection.size());
col_num=1;
for(WebElement tdElement : td_collection)
{
System.out.println("row # "+row_num+", col # "+col_num+ "text="+tdElement.getText());
col_num++;
}
row_num++;
}
}
}
Taking into consideration your second question. Investigated a lil bit workaround. One of the possibilities:
selenium.mouseDownRight(locator);
selenium.mouseUpRight(locator);
Another way:
WebElement elem = driver.findElement(By.xpath(".blablabla..")); //the element we want to //right click on
new Actions(driver).contextClick(elem).perform();
Other way is to use javascript.
So you get table cell as webElement. And then you right mouse click on it. Hope it works for you.
Upvotes: 1