![](/img/trans.png)
[英]Python+Appium+Android 6.0.1 - 'Click()' doesn't work
[英]Appium + Python on Android - scrolling doesn't work
Appium + Python on Android - 滾動 我有一個應用程序可以自動測試。 場景如下所示:
我點擊日期選擇器>日歷出現
我點擊年份 > 出現年份列表
我想滾動直到“1993”可見
屏幕上看不到“1993”年,我想繼續滾動直到它出現。 我試過了
TouchAction(driver).press(x=746, y=1351).move_to(x=755, y=588).release().perform()
^但我不想使用坐標,而且我必須多次重復該行。
def set_year(self):
visibility = self.driver.find_element(By.XPATH, "//android.widget.TextView[@text='1993']").is_displayed()
while not visibility:
TouchAction(self.driver).press(x=746, y=1351).move_to(x=755, y=588).release().perform()
visibility = self.driver.find_element(By.XPATH, "//android.widget.TextView[@text='1993']").is_displayed()
else:
print("not found")
^但它一直在拋出我 selenium.common.exceptions.NoSuchElementException:消息:使用給定的搜索參數錯誤無法在頁面上找到一個元素,因為正如我所說,它不可見
最好的方法是什么?
el = self.driver.find_element_by_xpath(<your_xpath>) driver.execute_script("mobile: scrollTo", {"element": el.id})
^這個給我一個錯誤,說元組沒有 id
每次找不到元素時,Appium 都會拋出錯誤。 因此,當您定義變量可見性時,您的腳本會在滑動之前停止。
嘗試這個:
def set_year(self):
visibility = False
i = 0
while not visibility or i<100:
i += 1
try:
visibility = self.driver.find_element(By.XPATH,
"//android.widget.TextView[@text='1993']").is_displayed()
except:
TouchAction(self.driver).press(x=746, y=1351).move_to(x=755,
y=588).release().perform()
if not visibility:
print("not found")
您的腳本將向下滾動,直到找到 1993 年。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.