我正在使用 Java 中的 Selenium WebDriver 在 Magento 站点上组合一个小应用程序来执行自动结账。我正在学习 Java,所以我坚持要使用 Java 解决这个问题,而不是切换到 Ruby 或 Python。
package com.huuginn.seleniumMagento;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
/**
* selenium app for completing checkout in magento
*
*/
public class App
{
public static void main( String[] args )
{
// MagentoCatalog c = new MagentoCatalog();
WebDriver driver = new FirefoxDriver();
driver.get("http://plmkt.huuginn.com/");
WebElement searchField = driver.findElement(By.id("search"));
System.out.println(searchField.getClass().getName());
searchField.clear();
searchField.sendKeys("sample");
searchField.submit();
}
}
Run Code Online (Sandbox Code Playgroud)
我的 getName() 行确认我正在从页面中获取我想要的元素。
编译时出现此错误:
[INFO] org.openqa.selenium.WebElement 中的编译失败 /seleniumMagento/src/main/java/com/huuginn/seleniumMagento/App.java:[25,13] sendKeys(java.lang.CharSequence...) 不能应用于 (java.lang.String) …