Windows自动化7️⃣元素位置发生变化,移动像素点击问题

元素位置发生变化, 可以先讲原来元素存储到一个变量, 然后通过这个变量去使用

 @pytest.mark.run(order=400016)
    @allure.title("@人员上限验证")
    def test_艾特人员上限验证(self):
        try:
            # 输入艾特
            self.driver.find_element(By.XPATH, '//Document[@Name="hwork-desktop-im"]/Group/Text').send_keys("@")
            all_name = self.driver.find_elements(By.XPATH,
                                                 '//Document[@Name="hwork-desktop-im"]/List/ListItem/Text[@Name="所有成员"]/parent::ListItem/following-sibling::ListItem/Text')

            # all_name 是一个变动的值 ,需要找一个list先存起来
            name_list = []
            for i in all_name:
                name_list.append(i.text)
            for j in name_list:
                self.driver.find_element(By.XPATH, '//Document[@Name="hwork-desktop-im"]/Group/Text').send_keys(j)
                pyautogui.press("enter")
                time.sleep(1)
                self.driver.find_element(By.XPATH, '//Document[@Name="hwork-desktop-im"]/Group/Text').send_keys("@")
            # 点击发送
            self.driver.find_element(By.XPATH, '//Button[@Name="发送"]').click()
            time.sleep(1)
            assert self.driver.find_element(By.XPATH, '//Document[@Name="hwork-desktop-im"]/Text[@Name="@'+name_list[-1]+'"]').is_displayed()

        finally:
            # 发送 Ctrl+A 来选择所有文本
            pyautogui.hotkey('ctrl', 'a')
            # 发送 Delete 来删除所选文本
            pyautogui.press('delete')
            self.driver.close()

元素无法定位, 可以通过已经定位到的元素进行px移动定位, 进行点击

    @pytest.mark.run(order=400014)
    @allure.title("移除/主动退群后,查看@人员列表")
    @allure.description("人员列表显示正确,退群人员不在@人员列表中")
    @pytest.mark.parametrize("条件", [("于文超")])
    def test_移除群后_查看艾特人员列表(self, 条件):
        try:

            time.sleep(1)
            self.driver.find_element(By.XPATH, '//Document[@Name="hwork-desktop-im"]/Text[7]').click()
            time.sleep(1)
            群里最后一个人 = self.driver.find_element(By.XPATH, '//Document[@Name="hwork-desktop-im"]/Custom/Image[last()]')
            ActionChains(self.driver).move_to_element(群里最后一个人).perform()
            time.sleep(1)

            # 鼠标向上移动20px
            pyautogui.move(0, -17, duration=0.25)
            # 接着鼠标向右移动20px
            pyautogui.move(19, 0, duration=0.25)
            # 执行点击操作
            pyautogui.click()

            time.sleep(1)
            self.driver.find_element(By.XPATH, '//Pane[@Name="Hwork"]/Document[@Name="Hwork"]/Button[@Name="确 定"]').click()
            time.sleep(3)
            # 光标输入框
            self.driver.find_element(By.XPATH, '//Document[@Name="hwork-desktop-im"]/Group/Text').click()
            self.driver.find_element(By.XPATH, '//Document[@Name="hwork-desktop-im"]/Group/Text').click()
            self.driver.find_element(By.XPATH, '//Document[@Name="hwork-desktop-im"]/Group/Text').send_keys("@"+条件)

            try:
                # 判断元素可见性
                element = self.driver.find_element(By.XPATH, '//Document[@Name="hwork-desktop-im"]/List/ListItem/Text[@Name="群成员"]')
                if element.is_displayed():
                    assert 1 > 2
            except NoSuchElementException:
                assert 1 == 1
        finally:
            pyautogui.hotkey('ctrl', 'a')
            pyautogui.press('delete')
            self.driver.close()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值