0
我想创建一个公共类来点击一个网页上的一个项目,只需将它传递给我使用的xpath和驱动程序。我希望能够只是做:添加一个公共类来点击Java使用xpath Selenium
ClickByXpath(driver, "/html/body/div/div[3]/form/div[2]/div[2]/div[1]/div[1]/div[3]/div/div[3]/div/input[1]");
下面是我使用的代码,但它的抱怨,该方法XPath字符串是不适用:
package TestPackage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Question {
public static void main(String[] args) throws Exception {
// The Firefox driver supports javascript
WebDriver driver = new FirefoxDriver();
// Go to google
driver.get("http://www.google.com");
//click in the searchbox
ClickByXpath(driver, "/html/body/div/div[3]/form/div[2]/div[2]/div[1]/div[1]/div[3]/div/div[3]/div/input[1]");
}
public static void ClickByXpath(WebDriver [] driverUsed , String[] XPath_to_click) throws Exception {
driverUsed.findElement(By.xpath(XPath_to_click)).click();
}
}
只是想知道为什么你会传递这两种类型的数组,而一次只能使用一个实例? – Saifur
感谢您的回复。我只是从这开始,所以无疑是做错了。他们是阵列吗,因为我用方括号? – Andrew