1

I am trying to automate a Test Case, but in one of the steps I have a table and I can´t handle it good.

Looking at the code with the development tools, I see a very large list where all the elements of the table are stored. In this link you can see an image of a small part of the code.

http://www.m-i-u.de/display-i94067b1tygv.html

In a certain row of the table is the element "Deadlocked" and I have to check whether in the 2 following rows there are 2 "Nein" (In this case both "Nine" are there)

The thing is that I dont have any ID and I don´t know how to locate this 3 words (Deadocked, Nein, Nein) in the code. Does anybody have any idea I could try? I would really appreciate any help

Thanks a lot Pablo

pablo casanovas
  • 128
  • 1
  • 2
  • 15
  • following-sibling xpath can help you. Please see if this post helps you. http://stackoverflow.com/questions/28541050/is-it-possible-to-get-next-sibling-using-csscontainingtext-in-protractor/28545758#28545758 – Sakshi Singla Apr 21 '15 at 10:54

2 Answers2

1

Firefox webDriver element locator plugin is very easy tool to locate elements in UI just by right clicking on elements. You will be able to get the set of selenium locators to identify elements mentioned.

https://addons.mozilla.org/en-us/firefox/addon/element-locator-for-webdriv/

0

Find all the elements using className attribute. An example:

List<WebElement> links = driver.findElements(By.className("c"));
links.get(0); //this will give Deadlocked
links.get(1); //this will give Nein
links.get(2); //this will give Nein

Using XPath:

List<WebElement> links = driver.findElements(By.xpath("//tr[@class=\"e\"]/th"));
links.get(0); 
links.get(1); 
links.get(2); 

Using cssSelector:

List<WebElement> links = driver.findElements(By.cssSelector("tr[@class=e] > th"));
links.get(0); 
links.get(1); 
links.get(2); 
LittlePanda
  • 2,496
  • 1
  • 21
  • 33
  • It becomes tough to handle if other rows in the table have columns with same class! @Pablo will be able to say about the html! – Sakshi Singla Apr 21 '15 at 10:59
  • @SakshiSingla: I have tried this xpath online. Lets wait for the OP to revert. – LittlePanda Apr 21 '15 at 11:09
  • Thanks a lot for the answer!, as Sakshi Singla said, I have many other elements with the same class. In the following photo http://www.m-i-u.de/images-i94076bsekve.jpg you see many lines with class "o" or "e". Almost allways there are "c" classes inside those lines – pablo casanovas Apr 21 '15 at 12:33
  • Then using xpath or css would be ok, but you will end up with more elements in your list. And you will have to iterate over that list to lookup for `Nein` and `Deadlocked`. – LittlePanda Apr 21 '15 at 12:35
  • What do in this case the cssSelector and xpath exactly do? Are them storing a list of 3 elements into every position of an another list? I mean, Do I have a list of lists? – pablo casanovas Apr 21 '15 at 14:04
  • I am doing this: List links_2 = driver.findElements(By.xpath("//tr[@class=\"e\"]/th")); System.out.println(links_2); And it is printing an empy list – pablo casanovas Apr 21 '15 at 14:08
  • Can you change the xpath to `//tr[@class=\"e\"]` and try? – LittlePanda Apr 22 '15 at 06:17