【求助】pycharm+appium 企业微信添加成员中,无法输入特殊字符格式的姓名

问题描述:

  1.问题背景:appium 企业微信实现练习中,想要编写异常情况的测试用例,即添加成员时,姓名处填写含有特殊字符的内容。
  2.复现步骤:手动输入时,输入特殊字符时,特殊字符不显示,且会出现如下toast提示:


3.自己尝试编写的用例,想直接使用sendkeys来传入特殊字符到姓名后面的必填处,然后直接定位toast,但是运行时在传入姓名时报错:
E selenium.common.exceptions.InvalidElementStateException: Message: Cannot set the element to ‘lll&^’. Did you interact with the correct element?

具体代码:

1.使用po实现,代码如下:

  编辑页面:
from appium.webdriver.common.mobileby import MobileBy
from appium.webdriver.webdriver import WebDriver
from appiumtest.test_contact_po.pages.base_page import BasePage

class EditMemberPage(BasePage):
    __ele_name = (MobileBy.XPATH,"//*[contains(@text,'姓名')]/.."
                                                "/*[contains(@text,'必填')]")
    __ele_phonenum = (MobileBy.XPATH,"//*[contains(@text,'手机')]/.."
                                                "//*[contains(@text,'必填')]")
    __save = (MobileBy.XPATH,"//*[@text='保存']")
    __noname_toast = (MobileBy.XPATH, "//*[contains(@text,'姓名不能为空')]")
    __misname_toast = (MobileBy.XPATH, "//*[contains(@text,'姓名只能由中英文字符及符号')]")
    __misphone_toast = (MobileBy.XPATH,"//*[contains(@text,'请填写合法的手机号')]")
    # 正常输入姓名和电话
    def edit_member(self,name,phonenum):
        # 1.输入姓名
        self.find_ele(*self.__ele_name).send_keys(name)
        # 2.输入手机
        self.find_ele(*self.__ele_phonenum).send_keys(phonenum)
        # 3.点击[保存]
        self.find_ele(*self.__save).click()
        from appiumtest.test_contact_po.pages.add_member_page import AddMemberPage
        return AddMemberPage(self.driver)

    # 输入含有特殊字符的姓名
    def misname_toast(self,name):
        # 1.输入姓名
        self.find_ele(*self.__ele_name).send_keys(name)
        self.find_ele(*self.__misname_toast)
   用例页面:
from appiumtest.test_contact_po.pages.app import App
from appiumtest.test_contact_po.utils.member_info import MemberInfo

class TestWework:
    def setup_class(self):
        self.memberinfo = MemberInfo()
        self.app=App()

    def setup(self):
        self.main = self.app.start().goto_main()

    def teardown(self):
        self.app.restart()

    def teardown_class(self):
        self.app.stop()

    # 添加联系人case--添加成功1
    def test_addmember_suc1(self):
        name = self.memberinfo.get_member_name()
        phonenum = self.memberinfo.get_member_phonenum()
        self.main.goto_contactpage().\
            goto_addmember().goto_editmember().\
            edit_member(name,phonenum).find_toast()

    # 添加联系人case--添加成功2
    def test_addmember_suc2(self):
        name = self.memberinfo.get_member_name()
        phonenum = self.memberinfo.get_member_phonenum()
        self.main.goto_contactpage().\
            goto_addmember().goto_editmember().\
            edit_member(name,phonenum).find_toast()
    # 输入特殊字符姓名
    def test_addmember_fail1(self):
        name = 'lll&^'
        self.main.goto_contactpage().\
            goto_addmember().goto_editmember().misname_toast(name)

上述代码中,运行test_addmember_fail1时,代码运行到编辑成员页面中,姓名处sendkeys就失败了,报错如下:
E selenium.common.exceptions.InvalidElementStateException: Message: Cannot set the element to 'lll&^'. Did you interact with the correct element?

想请问下,如何在姓名处输入特殊字符以便定位到上述图片中的错误toast呢?

看下元素定位,这个元素应该是不是输入框吧

是输入框的,可以正常输入汉字和英文字符的名字。但对于特殊字符而言,输入的同时会出现这个toast提示,且输入的特殊字符不显示。

关闭