seldom
seldom copied to clipboard
提供 通过子元素找父元素的方法
页面
<div>
<button onclick="ok()">
<span>确定</span>
</button>
</div>
<div>
<button onclick="cancel()">
<span>取消</span>
</button>
</div>
实现:
import seldom
class Test(seldom.TestCase):
def test_case2(self):
self.get("file:///Users/tech/klpro/github/seldom/test.html")
elems = self.get_elements(xpath="//div/button/span")
i = 0
for elem in elems:
if elem.text == "确定":
i = i
break
else:
i = i + 1
self.click(xpath="//div/button", index=i)
目前使用seldom的实现,比较麻烦,而且也不可靠,提供更加简单可靠的方法。
xpath 支持:
self.click(xpath="//div/button/span[contains(text(), '确定')]/..")