XPath定位时,使用文本的方法小技巧。

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()

上一篇:[动态规划]P1220 关路灯


下一篇:Dynamics 365 Online-使用Azure Logic App 与 Dynamics 365 集成