我遇到个奇怪的情况,进入 webview 后,使用 xpath 定位元素,运行脚本的时候最终点击的元素和我 xpath 定位的不一样(会向下偏移),程序也没报错,代码片段如下,我确保进入 webview 是成功的,而且我写的 xpath 也能定位到唯一元素,请问大家有遇到过这种情况情况?如何解决

@Test(group="buy1")
    def test01Buy(self):

        driver.switch_to.context('WEBVIEW_XXXXX)  # 进入webview

        # 通过selenium中的xpath操作元素
        from selenium.webdriver.common.by import By
        from selenium.webdriver.support.ui import WebDriverWait
        from selenium.webdriver.support import expected_conditions as EC
        locator_xpath = '//*[text()="资产明细"]'
        # 等待元素可见
        element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, locator_xpath)))
        # 滑动滚动条到某个指定的元素
        js4 = "arguments[0].scrollIntoView();"
        # 将下拉滑动条滑动到element区域
        driver.execute_script(js4, element)
        driver.find_element_by_xpath(locator_xpath).click()


↙↙↙阅读原文可查看相关链接,并与作者交流