1)//td[text()= "{0}" ] #这是一种非常常用的定位方法,具体例子使用如下:
__keyboard = '//td[text()= "{0}" ]'
__keyboard_dq = "//td[text()= '{0}' ]"
def click_keyboard(self, keyboard):
"""click single button on Virtual Keyboard"""
btn = ''
if keyboard == '"':
btn = self.__keyboard_dq.format(keyboard)
else:
btn = self.__keyboard.format(keyboard)
key = self.get_element(*(By.XPATH,btn))
key.click()
2)如果一个文本值不能确定,可以用两个条件限制选取:
__numpad_kb = '//td[contains(text(),"{0}") and contains(@id,"numKeys")]'
def click_numpad_kb(self, keyboard):
"""click single button on Numpad Keyboard"""
btn = self.__numpad_kb.format(keyboard)
key = self.get_element(*(By.XPATH,btn))
key.click()