我们如何在sendkeys中传递对象引用的值

时间:2017-06-22 04:36:25

标签: java selenium selenium-webdriver

我正在使用此

FirstViewController

那么,在这种情况下,我们如何在发送密钥中传递byte[] bytesDecode = Base64.decodeBase64(str.getBytes()); System.out.println("ecncoded value is " + new String(bytesDecode)); WebElement pass = driver.findElement(By.xpath("locator value")).sendkeys(bytesDecode); 的值?

2 个答案:

答案 0 :(得分:1)

我可以看到你犯了两个错误:

您的计划问题:

  1. WebElement pass = driver.findElement(By.xpath("locator value")).sendkeys(bytesDecode);
  2. 这是不正确的。它应该是:

    WebElement pass = driver.findElement(By.xpath("locator value"));
    
    1. 您无法直接传递bytesDecode。您必须在传递之前将其更改为字符序列。 它可以是

       pass.sendKeys(new String(bytesDecode,"UTF-8"));
      

答案 1 :(得分:0)

您可以通过以下代码将字节码转换为字符串;

WebElement pass = driver.findElement(By.xpath("locator value")).sendkeys(str);

然后在sendkays中传递该字符串:

class Type(Base):
     """
     Base class for "Type" tables
     "Type" tables are basically configuration tables with:
        key ====> id
        value ====> name
     Example usage:
         class RelationShipStatus(Type):
             __tablename__ = "relationship_status"
             __sequencename__ = "relationship_status_seq"


    status = RelationShipStatus()
    status.name = "Blocked"
    persist(status)

    Ensure to abstract the __tablename__ and __sequencename__ variables 
    to customise them
    __sequencename__ HAS to be defined in the child class
    __tablename__ is a magic sqlalchemy variable that will always have 
    to be defined in the child class
    """

    __abstract__ = True

    __sequencename__ = ""

    id = Column(
        SmallInteger, Sequence(__sequencename__),
        primary_key=True)
    name = Column(Unicode(20), unique=True)
    description = Column(Unicode(50))

    def __repr__(self):
        return ''' <{class_name}(id={self.id},name=
        {self.name})>'''.format(
        self=self, class_name=self.__class__.__name__)

    def __str__(self):
        return self.name

希望它能帮到你