如何为PrimeFaces编写Python selenium测试?
我试图编写一个Selenium测试,但问题是我已经了解到页面是用PrimeFaces生成的,因此元素ID会不时地随机变化。不使用IDs不是很可靠。我能做些什么吗?没有有意义的稳定ID不是问题,因为在页面上总是有其他方法来定位元素。仅举几个选项:如何为PrimeFaces编写Python selenium测试?,python,selenium,primefaces,Python,Selenium,Primefaces,我试图编写一个Selenium测试,但问题是我已经了解到页面是用PrimeFaces生成的,因此元素ID会不时地随机变化。不使用IDs不是很可靠。我能做些什么吗?没有有意义的稳定ID不是问题,因为在页面上总是有其他方法来定位元素。仅举几个选项: 部分id与XPath或CSS匹配,例如: # contains driver.find_element_by_css_selector("span[id*=customer]") driver.find_element_by_xpath("//s
- 部分id与XPath或CSS匹配,例如:
# contains driver.find_element_by_css_selector("span[id*=customer]") driver.find_element_by_xpath("//span[contains(@id, 'customer')]") # starts with driver.find_element_by_css_selector("span[id^=customer]") driver.find_element_by_xpath("//span[starts-with(@id, 'customer')]") # ends with driver.find_element_by_css_selector("span[id$=customer]")
- 引用/讲述有关数据类型的一些有价值信息的类(“面向数据的定位器”):
- 从标签横向移动:
# <label>Price</label><span id="65123safg12">10.00</span> driver.find_element_by_xpath("//label[.='Price']/following-sibling::span")
# <label>Price</label><span id="65123safg12">10.00</span>
driver.find_element_by_xpath("//label[.='Price']/following-sibling::span")
driver.find_element_by_link_text("Information")
driver.find_element_by_partial_link_text("more")