Selenium 硒、groovy、can';t执行任何click()、sendKeys()或类似功能
我不确定我的代码中缺少了什么。但我正在尝试运行一个基本的Groovy脚本,从页面中找到一个元素,然后单击它。 我的代码工作正常,可以添加Selenium 硒、groovy、can';t执行任何click()、sendKeys()或类似功能,selenium,groovy,automation,automated-tests,ready-api,Selenium,Groovy,Automation,Automated Tests,Ready Api,我不确定我的代码中缺少了什么。但我正在尝试运行一个基本的Groovy脚本,从页面中找到一个元素,然后单击它。 我的代码工作正常,可以添加.click()或.sendKeys()。 需要注意的是,我正在ReadyAPI上运行selenium。我已经按照他们帮助页面中的所有说明来确保在正确的文件夹中有正确的驱动程序 我的代码如下: import java.util.ArrayList; import org.openqa.selenium.* import org.openqa.selenium.B
.click()
或.sendKeys()
。
需要注意的是,我正在ReadyAPI上运行selenium。我已经按照他们帮助页面中的所有说明来确保在正确的文件夹中有正确的驱动程序
我的代码如下:
import java.util.ArrayList;
import org.openqa.selenium.*
import org.openqa.selenium.By
import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement
import org.openqa.selenium.chrome.ChromeDriver
def PATH_TO_CHROMEDRIVER = context.expand( '${PATH_TO_CHROMEDRIVER}' );
System.setProperty("webdriver.chrome.driver", PATH_TO_CHROMEDRIVER);
def WebDriver driver = new ChromeDriver();
driver.get("https://www.rakuten.com/");
WebElement loginButtonId = driver.findElementsByXPath("//*[@name='email_address']");
loginButtonId.click();
driver.close();
return
我得到的错误消息如下:
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '[]' with class 'java.util.ArrayList' to class 'org.openqa.selenium.WebElement' due to: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: org.openqa.selenium.WebElement() error at line: 12
如果这里有人能帮忙,我将不胜感激。
谢谢,您的错误在这一行:
WebElement loginButtonId = driver.findElementsByXPath("//*[@name='email_address']");
findElements
需要检测元素列表时应使用,
如果要获取单个元素,请使用findElement
:
WebElement loginButtonId = driver.findElementByXPath("//*[@name='email_address']");
非常感谢。我完全迷路了,我错过了!