OS : Windows 10
Browser : Firefox 61
Selenium Version 3.13
Code :
package PhpTravelsPackage;
//import java.awt.List;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.By.ByClassName;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxDriverLogLevel;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.WebElement;
public class phpTravels {
public static void main (String args[]) {
System.setProperty("webdriver.gecko.driver","C:\\\\Marionette\\geckodriver.exe");
FirefoxOptions options = new FirefoxOptions();
options.setLogLevel(FirefoxDriverLogLevel.DEBUG);
WebDriver driver = new FirefoxDriver(options);
driver.get ("https://www.phptravels.net/");
WebElement link = null;
int linksCount = 0 ;
Actions actions = new Actions(driver);
actions.moveToElement(driver.findElement(By.id("li_myaccount"))).perform();
}
}
错误:
(Program successfully opens the website, but does not perform the action instructed)
Exception in thread "main" org.openqa.selenium.WebDriverException: TypeError: rect is undefined
Build info: version: '3.13.0', revision: '2f0d292', time: '2018-06-25T15:32:14.902Z'
System info: host: 'ADMIN-PC', ip: '192.168.1.7', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_181'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 61.0.1, javascriptEnabled: true, moz:accessibilityChecks: false, moz:headless: false, moz:processID: 9652, moz:profile: C:\Users\admin\AppData\Loca..., moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: XP, platformName: XP, platformVersion: 10.0, rotatable: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}}
Session ID: a8b8b5b6-d384-4c35-80f6-9d32bdaa428c
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
at org.openqa.selenium.remote.RemoteWebDriver.perform(RemoteWebDriver.java:614)
at org.openqa.selenium.interactions.Actions$BuiltAction.perform(Actions.java:638)
at org.openqa.selenium.interactions.Actions.perform(Actions.java:594)
at PhpTravelsPackage.phpTravels.main(phpTravels.java:30)
最佳答案
如果您想在打开URL后点击我的帐户按钮,那么您可以尝试此代码:
请注意,此id li_myaccount
不是唯一。 DOM 中存在两个 Web 元素。
WebElement myAccount = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@id='collapse']/descendant::ul[3]/li[@id='li_myaccount']/a")));
myAccount.click();
关于java - Selenium-Java-Actions 类型错误 : rect is undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51579959/