appium手机端浏览器元素定位不到

“”"
def init(self):
desire_caps={
“platformName”:“Android”,
“platformVersion”:“8.0.0”,
“deviceName”:“a5d86a3b”,
#“appPackage”:“com.android.chrome”,
#“appActivity”:“org.chromium.chrome.browser.ChromeTabbedActivity”,
“browserName”:“Chrome”,
“noReset”:“true”,
#是否需要输入非英文之外的语言并在测试完成后重置输入法
“unicodeKeyBoard”:“true”,
“resetKeyBoard”:“true”,
#跳过安装、权限设置等操作
“skipDeviceInitialization”:“true”
}
self.driver=webdriver.Remote(“http://127.0.0.1:4723/wd/hub”,desire_caps)
self.driver.implicitly_wait(10)
self.driver.get(“http://www.baidu.com”)
self.driver.find_element_by_id(“index-kw”).click()
“”"
报错内容:
Traceback (most recent call last):
File “F:/UI_test/landing_pro/pages/basepage.py”, line 58, in
base.get_page()
File “F:/UI_test/landing_pro/pages/basepage.py”, line 50, in get_page
self.driver.find_element_by_id(“index-kw”).click()
File “C:\Users\cuixin\venv\landing_pro\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 360, in find_element_by_id
return self.find_element(by=By.ID, value=id_)
File “C:\Users\cuixin\venv\landing_pro\lib\site-packages\appium\webdriver\webdriver.py”, line 279, in find_element
return self.execute(RemoteCommand.FIND_ELEMENT, {
File “C:\Users\cuixin\venv\landing_pro\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 321, in execute
self.error_handler.check_response(response)
File “C:\Users\cuixin\venv\landing_pro\lib\site-packages\appium\webdriver\errorhandler.py”, line 31, in check_response
raise wde
File “C:\Users\cuixin\venv\landing_pro\lib\site-packages\appium\webdriver\errorhandler.py”, line 26, in check_response
super().check_response(response)
File “C:\Users\cuixin\venv\landing_pro\lib\site-packages\selenium\webdriver\remote\errorhandler.py”, line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: invalid locator
(Session info: chrome=81.0.4044.117)

Appium后台的日志输出:


Appium版本:1.4.16

看下你的导包

image

看看代码上import的内容

from appium import webdriver
from time import sleep
from appium.webdriver.common.mobileby import MobileBy
from selenium.webdriver.common.by import By

目前我改成xpath定位元素可以的,用id不行