0

I have searched several questions but I didn't figure out my problem:

I want to test/verify configuration pages of 2 systems. But I faced 3 challenges:

1.The pages for 2 systems look same at all, but actually the dom/xPath info of same items(text,drop-down list, radio button and so on) are totally different. For example, the "Device Name" fields of 2 systems on the page have 2 different xPath, such as xPath of sys1 is "//input/abc" and xPath of sys2 is "//input/xyz".

2.Sometimes the page is generated dynamically so the dom/xPath of the same item of one system may be different at different time.

3.Based on 1 & 2, it's difficult of me to write one script to run on all systems(we'll have more system in the future). I don't want to define different xpath/dom database for different systems.

My question is:

1.Can selenium return how many “text field" "drop-down list" "radio button" objects on the page?

2.Can selenium return xPath/dom of each objects in Question1?

I hope selenium can return all objects and xPath/dom info of each object, so that I can make a mapping and call for different systems(I can decide which xPath is currently using by comparing the Index/Location of "same" objects).

Appreciate for all comments/help.

David Wu
  • 681
  • 2
  • 7
  • 9

2 Answers2

0

I don't know c#, but for Java there is a driver.findElements(By.xpath/css(xpath/css value))). This will return you the number of elements in the page. If its a textbox that you have to find you can use something like

driver.findElements(By.xpath(//input[@type='textbox']).size();

This will return the number of textboxes in the page.

For question 2 - Check this. There was a similar question asked in SO.

How to calculate the XPath position of an element using Javascript?

Community
  • 1
  • 1
A.J
  • 4,899
  • 2
  • 25
  • 36
  • Thanks. If the page contains 10 textbox, 5 drop-down list. Do you know how to get the xpath of each of them? I need to make a mapping of each object and its xpath/dom/css or something that Selenium can handle. – David Wu Jun 18 '12 at 05:37
0

You can use Linq for something like this. For example, getting all input elements can be done via:

IWebDriver driver = new FirefoxDriver();
var inputElements = driver.FindElements(By.TagName("input")); // get all input elements
inputElements.Count(); // get how many input elements there are

or:

IWebDriver driver = new FirefoxDriver();
var inputElements = driver.FindElements(By.XPath("//input")); // get all input elements
inputElements.Count(); // get how many input elements there are
Arran
  • 22,804
  • 6
  • 63
  • 75