【问题标题】:Problem with mobile auto-test python+appium+selenium移动自动测试python+appium+selenium的问题
【发布时间】:2021-08-27 13:12:44
【问题描述】:

我是移动自动化的新手。我以为我明白了要点,但我遇到了一个问题。 使用命令 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()

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

【问题讨论】:

    标签: python android selenium appium python-appium


    【解决方案1】:

    您可以使用 ActionChains 类提供的 send_keys 方法,而不是使用默认的 send_keys 方法

    从 selenium.webdriver 导入 ActionChains

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

    【讨论】:

      猜你喜欢
      • 2016-08-23
      • 2020-05-02
      • 2018-04-29
      • 2016-12-27
      • 2020-12-31
      • 2020-10-05
      • 2020-06-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多