■質問内容
seleniumとは直接関係ないかもしれませんが、
テストシナリオの利便性のため、XMLにxpathにてテストシナリオを記述し、JAVAのパーサにて
拾いにいくというコーディングをしたのですが、下記のエラーが発生しております。
Exception in thread "main" org.openqa.selenium.InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression //*[@id=\"categoryHead_mech\"]/a because of the following error:
SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//*[@id=\"categoryHead_mech\"]/a' is not a valid XPath expression.
普通に下記のとおり書けば、問題なく実行されます。
driver.findElement(By.xpath("//*[@id=\"categoryHead_mech\"]/a")).click();
XMLの記述形式がおかしいのか、それとも、セレニウム側の問題なのか、分からない状況です。
解消方法について、ご教示お願いできないでしょうか?
■読み込むXMLは下記のとおりです。
<?xml version="1.0" encoding="UTF-8"?>
<testcase1>
<shinario1>/html/body/div[1]/div[2]/div/div[7]/h2</shinario1>
<shinario2>//*[@id=\"categoryHead_mech\"]/a</shinario2>
</testcase1>
■JAVA側は抜粋すると
private void tracenode(Node node){
Node child = node.getFirstChild();
while(child != null){
printTextNode(child);
tracenode(child);
child = child.getNextSibling();
}
}
public void printTextNode(Node node){
if(node.getChildNodes().getLength() == 1){
String ch = "";
ch = node.getTextContent();
System.out.println("ノードの値:" + ch);
driver.findElement(By.xpath(ch)).click();
}
}
になります。
宜しくお願い致します。