문제

I was wondering what are the common approaches for dealing with extremely long locators using robotframework and/or selenium?

I'm talking about locators that long:

<input id="all00$SPWebExample1$g_bcd023df_3ba6_4f8f_bef3_164383c266aa$ctl00$$HereComesAnotherText1$rblFoundIs" />

The obvious approach is to "hide" them in the resource files so they don't pollute the test case files. Another approach I've seen is to create a static xml file containing a full structure of a tested website and parse the xml file (I can provide example if needed).

Are there any better ways to do this?

도움이 되었습니까?

해결책

If the ids are being generated automatically, then it isn't a good idea to store them in a long locator like that.


Instead of:

string superLongLocatorID = "all00$SPWebExample1$g_bcd023df_3ba6_4f8f_bef3_164383c266aa$ctl00$$HereComesAnotherText1$rblFoundIs"

Use:

string xpathLocator = "//input[contains(@id, 'rblFoundIs')]"

The XPath version is considerably shorter, and won't be as easily breakable as storing the full ID.

If there are multiple input elements that contain the same text, then there are other ways to narrow down the result.

다른 팁

The solution IMHO is not to use ugly autogenerated IDs. Your tests will end up brittle because they will all break if the framework changes the ID generation method. Instead, use XPath or CSS selectors.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top