最近在用selenium给项目添加自动化测试模块,遇到以下问题以及解决办法,backup,也许以后还会用到。
Q1 : Some elements id is generated automatically ext-gen in JS code, when the script run in the second times, the id recorded in the first time could not be found.
A1 : There are two solutions here,
- Add fixed id for the elements you are going to test in source code instead of being generated automatically.
- Use the parent node to identify a location and then using tag as road map to index to where you want. For example,
Target = ext-gen112
Can be changed into,
Target = //div[@id='testJsonsMenu']/ul/li[3]/a/span
We use a fix id testJsonsMenu to identify one location, then go down to find the element in the tree.
Q2 : Because of network slowness or application performance issue, sometimes, page response was not so quick that popup menu has not come out. So when selenium to run the next step, some element might not be found, missing error occur.
A2 : Tow solutions,
- Let selenium know the application was not that fast-run. If you are in selenium IDE, you could just drag slider from fast to slow in the main page.
- If you are in the programming code, you could set wait() or speed. I like the second one, for example, in java,
selenium .setSpeed( "1000" ); time unit is millisecond,
This means every step in your code will be run behind 1 second after the previous step is simulated.