手机自动测试python+appium+selenium的问题

问题描述

我是移动自动化的新手。我以为我明白了要点,但我遇到了一个问题。 使用命令 send_keys() 时出现错误 selenium.common.exceptions.InvalidElementStateException:消息:无法将元素设置为“321785214”。您是否与正确的元素进行了交互?

我有一个代码

driver = webdriver.Remote("http://localhost:4723/wd/hub",desired_cap)
# Skip fingerprint
driver.find_element_by_xpath("//android.widget.Button[@bounds='[413,1802][668,1877]']").click()

# Click Continue
driver.find_element_by_xpath("//android.widget.Button[@content-desc='Continue']").click()

# Click to input phone number
input_phone_number = driver.find_element_by_xpath("//android.widget.EditText").click()

input_phone_number_edit = driver.find_element_by_class_name("android.widget.EditText")

# Enter phone number
input_phone_number_edit.send_keys("321785214")

我有来自其他移动应用程序的代码,此代码正在运行

driver = webdriver.Remote("http://localhost:4723/wd/hub",desired_cap)
# click to Set up later button
set_up_later_btn = driver.find_element_by_xpath('//android.widget.Button[@content-desc="Set up later"]').click()

input_phone_number = driver.find_element_by_xpath('//android.view.View[@content-desc="Phone number"]').click()

input_phone_number_edit = driver.find_element_by_class_name('android.widget.EditText')
driver.implicitly_wait(50)

input_phone_number_edit.send_keys('178546128')

driver.find_element_by_accessibility_id("Continue").click()

我不知道为什么第一个代码不起作用。我需要帮助。谢谢

解决方法

您可以使用 ActionChains 类提供的 send_keys 方法代替默认的 send_keys 方法

从 selenium.webdriver 导入 ActionChains

actions = ActionChains(self.driver)
        actions.send_keys("321785214")
        actions.perform()

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...