简体   繁体   English

在Selenium Webdriver中处理表格

[英]Handle a table in Selenium Webdriver

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.miu.de/display-i94067b1tygv.html http://www.miu.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) 在表的特定行中,元素“已死锁”,我必须检查接下来的2行中是否有2个“ Nein”(在这种情况下,两个“ Nine”都存在)

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. 问题是我没有任何ID,也不知道如何在代码中找到这3个字(Deadocked,Nein,Nein)。 Does anybody have any idea I could try? 有人知道我可以尝试吗? I would really appreciate any help 我真的很感谢任何帮助

Thanks a lot Pablo 非常感谢Pablo

Firefox webDriver element locator plugin is very easy tool to locate elements in UI just by right clicking on elements. Firefox webDriver元素定位器插件是非常简单的工具,只需右键单击元素即可在UI中定位元素。 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/ https://addons.mozilla.org/en-us/firefox/addon/element-locator-for-webdriv/

Find all the elements using className attribute. 使用className属性查找所有元素。 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 : 使用XPath

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

Using cssSelector : 使用cssSelector

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM