【发布时间】:2020-07-10 09:06:16
【问题描述】:
我不确定我的代码中缺少什么。但我正在尝试运行一个基本的 Groovy 脚本,在该脚本中我从页面中找到一个元素,然后单击它。
我的代码有效,以至于我添加了.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
如果有人可以在这里提供帮助,我将不胜感激。 谢谢,
【问题讨论】:
标签: selenium groovy automation automated-tests ready-api