gpt4 book ai didi

java - selenium webdriver 中的弹出窗口中的图像不可点击

转载 作者:行者123 更新时间:2023-12-02 13:16:18 25 4
gpt4 key购买 nike

我有一个弹出窗口,如下所示,

__________________
| Label 1 +<--this is a plus img
| |
| Label 2 + |
|________________|

我想点击那个加号图像,但是当我尝试执行此操作时出现一个异常,

org.openqa.selenium.WebDriverException: unknown error: Element <div class="popupActionsLabel">...</div> is not clickable at point (1012, 133). Other element would receive the click: <div class="popupActionsLabel">...</div>
(Session info: chrome=58.0.3029.96)
(Driver info: chromedriver=2.27.440175 (9bc1d90b8bfa4dd181fbbf769a5eb5e575574320),platform=Linux 4.4.0-75-generic x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 72 milliseconds
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'PC-3', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-75-generic', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.27.440175 (9bc1d90b8bfa4dd181fbbf769a5eb5e575574320), userDataDir=/tmp/.org.chromium.Chromium.5Z2sYt}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=58.0.3029.96, platform=LINUX, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=}]
Session ID: 2da36c1282dd134e5dec3c9024e86c48
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:638)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:274)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:84)
at com.trupublic.client.util.Thing.formShortcuts(Thing.java:240)
at com.trupublic.client.restauranttapp.thing.MenuItemThingTest.testMenuItemThing(MenuItemThingTest.java:124)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

我已经实现了我的代码如下,

    Webelement popup = driver.findElement(By.className("popupMainVPanel_CCPopupView"))

//This popup contains a list of web elements which I am taking as follow,

List<Webelement> popupWebElementList = popup.findElements(By.className("actionLabelHPanel"));

String parentWindowHandler = driver.getWindowHandle(); // Store your parent window
Thread.sleep(3000);
switchToPopup();
Thread.sleep(3000);

for (WebElement element : popupWebElementList) {

WebElement label1 = element.findElement(By.className("popupLabel"));
Thread.sleep(3000);

WebElement label1Img = element.findElement(By.className("popupImg"));
Thread.sleep(3000);

if (label1.getText().equals("Label1")
&& label1Img.getAttribute("title").equals("Create Label1")) {
Thread.sleep(3000);
label1Img.click();// at this line i am getting exception
}
}


public void switchToPopUp() {
try {

String subWindowHandler = null;

Set<String> handles = driver.getWindowHandles(); // get all window handles
Iterator<String> iterator = handles.iterator();
while (iterator.hasNext()) {
subWindowHandler = iterator.next();
}
driver.switchTo().window(subWindowHandler); // switch to popup window perform operations on popup
} catch (Exception e) {
logger.log(Level.SEVERE, "Exception Occured in createActionForThing() ", e);
}
}

即使出现此异常,我也能够获取所有网络元素。

最佳答案

由于元素未收到点击,因此您需要首先使用 actions 类移动到该元素,然后单击该元素。

   Actions act = new Actions(driver);
act.moveToElement(label1Img).build().perform();
label1Img.click();

关于java - selenium webdriver 中的弹出窗口中的图像不可点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43758009/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com