51Testing软件测试论坛

标题: 写了个appium+python程序,元素定位报错,求解 [打印本页]

作者: qq245124928    时间: 2016-11-30 11:30
标题: 写了个appium+python程序,元素定位报错,求解
#!/usr/bin/env python
# -*- encoding:utf-8 -*-
import sys
import os
import time
import unittest
from appium import webdriver
from lib2to3.pgen2.driver import Driver
from lib2to3.tests.support import driver
PATH=lambda ps.path.abspath(os.path.join(os.path.dirname(__file__),p))

desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '4.4.3'
desired_caps['deviceName'] = 'HMB1AMBG'

#desired_caps['app'] = PATH('F:\\GalanzCloud_2.0.5.3.apk')
desired_caps['appPackage'] = 'com.galanz.view'
desired_caps['appActivity'] = 'com.galanz.view.SplashActivity'
#desired_caps['automationName'] = 'Selendroid'
print desired_caps
#如果设置的是app在电脑上的路径,则不需要配appPackage和appActivity,同理反之
#启动app
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

#启动app时,需要一定时间进入引导页,所以必须设置等待时间,不然下面会一直报错定位不到元素
time.sleep(5)
driver.get_window_size()
print driver.get_window_size()
time.sleep(5)
#driver.background_app(5)
#driver.launch_app()
#print(driver.current_activity)
a = driver.find_element_by_name("G")
#print

#driver.quit()

作者: qq245124928    时间: 2016-11-30 11:31
appium  version:1.4.16.11
作者: qq245124928    时间: 2016-11-30 11:32
报错:
C:\Python27\python.exe C:/text/apptest/appium1.py
{'platformVersion': '4.4.3', 'deviceName': 'HMB1AMBG', 'platformName': 'Android', 'appActivity': 'com.galanz.view.SplashActivity', 'appPackage': 'com.galanz.view'}
{u'width': 480, u'height': 854}
Traceback (most recent call last):
  File "C:/text/apptest/appium1.py", line 34, in <module>
    a = driver.find_element_by_name("G")
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 365, in find_element_by_name
    return self.find_element(by=By.NAME, value=name)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 752, in find_element
    'value': value})['value']
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
    self.error_handler.check_response(response)
  File "C:\Python27\lib\site-packages\appium\webdriver\errorhandler.py", line 29, in check_response
    raise wde
selenium.common.exceptions.NoSuchElementException: Message: An element could not be located on the page using the given search parameters.

作者: Miss_love    时间: 2016-11-30 13:27
qq245124928 发表于 2016-11-30 11:32
报错:
C:\Python27\python.exe C:/text/apptest/appium1.py
{'platformVersion': '4.4.3', 'deviceName' ...

An element could not be located on the page using the given search parameters.
作者: Bugkiller    时间: 2016-11-30 13:34
沙发
作者: lamecho    时间: 2017-3-17 13:45
a = driver.find_element_by_name("G")这句问题
尽量避免用这个方法去找元素(by name)
多去用find_element_by_id(),去看看你要找的这个G元素的id是什么!
作者: quhuayin    时间: 2017-4-6 10:23
byname('G') 可能这个页面 有许多name 为G 这样定位不准确,有id 用id,或xpath




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2