51Testing软件测试论坛

标题: python+splinter如何定位动态ID的按钮 [打印本页]

作者: sterson    时间: 2018-3-5 14:21
标题: python+splinter如何定位动态ID的按钮
<button id="vbase_login_loginVBASE_JGButton1_8a819ea061eacc110161f4c00f666f0a" widgetcode="JGButton1" type="button" class="btn btn-primary btn-lg btn-block " style="text-align:Center">登录</button>
如上标签,ID的值后面是动态生成的,每次都不一样
试了方法一:
btn=bs.find_by_text('登录')
btn[0].click
btn[1].click

按上面的写法,不会点击,print(btn),如下:
[<splinter.driver.webdriver.WebDriverElement object at 0x000000000E941FD0>, <splinter.driver.webdriver.WebDriverElement object at 0x000000000E941EF0>]

试了方法二:
bs.find_by_xpath("//*[starts-with(@id, 'vbase_login_loginVBASE_JGButton1')]")[1].click
报这个错:
no elements could be found with xpath "//*[starts-with(@id, 'vbase_login_loginVBASE_JGButton1')]"

请问大神,还有什么办法?






欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2