【发布时间】:2018-02-15 15:36:45
【问题描述】:
如果您打开此链接 https://www.phptravels.net/ 它显示进度条之类的东西,然后您将在右上角看到“酒店”选项。我也尝试过隐式等待、WebDriverWait 和流利的等待。当我使用 element.isDisplayed() 时,它显示“true”,但是当我执行点击操作时,它会抛出异常。
driver.manage().window().maximize();
driver.get("https://www.phptravels.net/");
String hotelsXpth = "//ul[@class='main-menu go-left RTL']/li/a/span[contains(text(),'Hotels')]";
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath
(hotelsXpth)));
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(
hotelsXpth)));
System.out.println(driver.findElement(By.xpath(hotelsXpth)).isDisplayed());
driver.findElement(By.xpath(hotelsXpth)).click();
异常
org.openqa.selenium.WebDriverException: unknown error: Element <span>...
</span> is not clickable at point (705, 130). Other element would receive
the click: <div id="preloader" class="loader-wrapper">...</div>
(Session info: chrome=63.0.3239.132)
(Driver info: chromedriver=2.33.506120
(e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 10.0.14393
x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-
01T18:33:54.468Z'
System info: host: 'D-113060768', ip: '10.149.34.102', os.name: 'Windows
10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptSslCerts: true, applicationCacheEnabled: false,
browserConnectionEnabled: false, browserName: chrome, chrome:
{chromedriverVersion: 2.33.506120 (e3e53437346286..., userDataDir:
C:\Users\AS337139\AppData\L...}, cssSelectorsEnabled: true, databaseEnabled:
false, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true,
locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents:
true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform:
XP, platformName: XP, rotatable: false, setWindowRect: true,
takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: ,
unhandledPromptBehavior: , version: 63.0.3239.132, webStorageEnabled: true}
Session ID: bbfef8e4da0b2a6b98181d54c454d504
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)
有什么建议吗?
【问题讨论】:
-
以下链接处理您的问题:stackoverflow.com/questions/11908249/…
-
@Ashraf Mulla ,尝试从this answer 实施解决方案,只需使用
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.id("preloader")));代替 -
不是
wait的问题,问题是你的xpath
标签: selenium selenium-webdriver automation wait