Appium 切換進入 webview,點選元素偏離

yee發表於2020-06-11

我遇到個奇怪的情況,進入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()

相關文章