我以前点击该元素的不同方式是,
driver.findElement(By.xpath(".//*[@value=.,"+NewStateName+"]")).click();
driver.findElement(By.cssSelector(".//*[@value=.,'"+NewStateName+"']")).click();
driver.findElement(By.value(NewStateName));
driver.findElement(By.linkText(NewStateName));
driver.findElement(By.xpath("//span[contains(.,"+NewStateName+")]"));
In above code 'NewStstaeName is a string variable for which the value is dynamically generated during run time.
Error returned:
org.openqa.selenium.InvalidSelectorException: The given selector .//*[@value=.,NEWSTATEABC21M] is either invalid or does not result in a WebElement. The following error occurred:
答案 0 :(得分:0)
我认为你需要围绕NewStateName的值引用,试试这些:
driver.findElement(By.xpath(".//*[@value=.,'"+NewStateName+"']")).click();
driver.findElement(By.xpath("//span[contains(.,'"+NewStateName+"')]"));
结果选择器将如下所示:
.//* [@值=,' NEWSTATEABC21M']