I’m using WebDriver to retrieve and autofill forms in Firefox in the following way.
FirefoxDriver driver = new FirefoxDriver();
List<WebElement> inputElements = driver.findElementsByTagName("input");
List<WebElement> selectElements = driver.findElementsByTagName("select");
List<WebElement> allElements = new ArrayList<WebElement>(inputElements);
allElements.addAll(selectElements);
When I cycle through the allElements List, I first see all the ‘input’ elements, then all the ‘select’ elements. Is there a way to retrieve all these elements in the order they occur on the page? I wish findElementsByTagName() would take a REGEX like:
driver.findElementsByTagName("(input|select)");
Any clever ways to do this?
You should look into using xPaths. They should give you all the functionality you will need.