将字符串转换为 WebElement [英] convert String to WebElement

查看:44
本文介绍了将字符串转换为 WebElement的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将 WebElement 的字符串表示转换为 WebElement?

Is it possible to covert the string representation of a WebElement to a WebElement?

所以如果这是一个类变量:

So if this is a class variable:

@FindBy(css = "select[id*='budTbl:0:j_id544']") 
WebElement roleList1;

并且有一个字符串设置为 roleList1

And there's a string set to roleList1

是否可以将字符串转换为WebElement roleList1,以便在诸如

Can the string be converted to the WebElement roleList1 so that it can be used in a statement such as

new Select(roleList1).getFirstSelectedOption().getText()

推荐答案

没有.字符串到 Webelement 的转换非常棘手.它需要dom和所有知识

No. String to Webelement conversion is very tricky. It needs dom and all knowledge

但是如果您只想比较页面上是否存在相同名称的元素,请使用下面的

but if you just want to compare that same name element present on page or not then use below

public boolean methodname(String element_string_name)
{ 
val = false;
if (element_string_name.equals("string_name")) {
                element_name.isDisplayed();
                val = true;
}
return val;
}

这篇关于将字符串转换为 WebElement的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆