How to convert string to By type

后端 未结 4 1784
春和景丽
春和景丽 2021-01-27 06:43

How to convert String to By type.

Following is my scenario: Keep object identification in Properties file in below manner

username=By.id(\"username\")
pa         


        
4条回答
  •  天命终不由人
    2021-01-27 07:16

    You have to evaluate the entire expression within the context of existing code. You should framework such as JEXL or expressionoasis

    Code below uses JEXL

    // Create JexlEngine instance
    JexlEngine jexl = new JexlEngine();
    // Create Expression object for the string
    Expression e = jexl.createExpression(prop.getProperty("username"));
    
    // Create a context. You can pass reference to any object you want to use inside the expression
    JexlContext jc = new MapContext();
    
    // Now evaluate the expression, getting the result
    driver.findElement((By)e.evaluate(jc)); 
    

提交回复
热议问题