问题
I have been using Selenium in my DEV environment. When I go to try some of my recorded tests on my Test environment, I find that the elements have different IDs (they are generated by the web framework). I can change the test manually to use
document.forms[2].elements[3]
instead of by id, which looks like this:
ellaMform:j_id77
I'm looking for a way to tell selenium to record the dom:index value for the controls so that tests will be the same between DEV and TEST.
Similar question on SO points to a plugin but is not exactly what I need: Make Selenium record IDs, not paths
回答1:
IDE already has locator builders for several DOM styles (e.g., dom:index
, which matches your model, or dom:name
, which is less position-oriented). By default, they are prioritized lower than ID locators, but you can choose which locator you want to use when you record the test.
来源:https://stackoverflow.com/questions/6207454/can-i-tell-selenium-to-record-in-dom-mode-instead-of-element-id-mode