正在使用JAVA处理selenium webdriver!
我正在尝试使用变量exp
动态传递字符串String exp=",,,4'-TETRA; P-CHLORIDE";
d.findElement(By.xpath("a[contains(text(),\""+exp+"\")]//ancestor::table//parent::div")).sendKeys(Keys.ARROW_DOWN);
但它给了我一个错误:
Unable to locate element: {"method":"xpath","selector":
"a[contains(text(),\",,,4'-TETRA; P-CHLORIDE\")]//ancestor::table//parent::div"
}
答案 0 :(得分:2)
使用'"+exp+"'
代替\""+exp+"\"
:
d.findElement(By.xpath("a[contains(text(),'"+exp+"')]//ancestor::table//parent::div")).sendKeys(Keys.ARROW_DOWN);
<强>更新强>
d.findElement(By.xpath('a[contains(text(),"'+exp+'")]//ancestor::table//parent::div')).sendKeys(Keys.ARROW_DOWN);