Selenium Webdriver(Java)-将classname值保存到变量中
我需要以某种方式将classname值-Selenium Webdriver(Java)-将classname值保存到变量中,java,selenium,Java,Selenium,我需要以某种方式将classname值-class=\“system Win7\”存储到变量中 new WebDriverWait(Login.driver,20).until(ExpectedConditions.visibilityOfElementLocated (By.xpath("//div[@class=\"system Win7\"]"))) 我希望在选择具有相同类名的特定单选按钮后使用此变量 例如: 1) 保存类名: String v
class=\“system Win7\”
存储到变量中
new WebDriverWait(Login.driver,20).until(ExpectedConditions.visibilityOfElementLocated
(By.xpath("//div[@class=\"system Win7\"]")))
我希望在选择具有相同类名的特定单选按钮后使用此变量
例如:
1) 保存类名:
String v_test = new WebDriverWait(Login.driver,20).until(ExpectedConditions.visibilityOfElementLocated
(By.xpath("//div[@class=\"system Win7\"]"))).getSmth();
2) 然后使用v_测试查找并单击单选按钮
Login.driver.findElement
(By.xpath("//div[@class="+v_test+"]")).click();
getAttribute()
将为您提供所使用属性的值
String v_test = new WebDriverWait(Login.driver,20).until(ExpectedConditions.visibilityOfElementLocated (By.xpath("//div[@class=\"system Win7\"]"))).getAttribute("class")
你已经试过什么了?谢谢你,这就是我要找的。你能告诉我,我如何从v_测试变量中分割结果吗?我的意思是,v_测试包含“system Windows 64位”,是否可以只在该变量中存储64位?其他信息:在上述情况下,我现在不知道变量中会出现什么结果。所以,我只想得到第三个单词。使用
Split
可以完成这一点。使用string[]myVar=v_test.Split(“”);字符串targetVar=myVar.Last()
以空格分隔并获取targetVar,它是索引为2的最后一个元素。让我知道这是否清楚或者你也可以做string[]myVar=v_test.Split(“”);字符串targetVar=myVar[myVar.Count()-1])
谢谢您,没问题。我把它转换成Java,它是一样的。因此,我使用:string[]myVar=v_test.Split(“”);字符串targetVar=myVar[2];