无法检查第二个复选框。获取org.openqa.selenium.WebDriverException:未知错误:元素在点(106,655)处无法点击

时间:2016-11-30 15:38:17

标签: selenium selenium-webdriver

我在尝试选择列表中的第二个复选框时收到WebDriverException。我可以选择第一个复选框,但第二次我的代码抛出异常。请找到我正在使用的方法和下面的异常消息。 注意:任何建议对我都有帮助。

网址:https://www.snapdeal.com/products/computers-external-hard-drives?sort=plrty&q=Capacity_s%3A1%20TB%7C

public void capacitySelection(String capacity){
        WebDriverWait wd = new WebDriverWait(driver, 180);
        List<WebElement> cList = wd.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//div[@data-name='Capacity_s']/div")));
        int i=1;
        for(WebElement we:cList){
            WebElement select= wd.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[@data-name='Capacity_s']/div["+ i++ +"]/label")));
            if(select.getText().contains(capacity)){
                select.click();
                break;
            }
        }
    }

Exception Message:
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Element is not clickable at point (106, 655). Other element would receive the click: <label for="Capacity_s-3TB">...</label>
  (Session info: chrome=54.0.2840.99)
  (Driver info: chromedriver=2.24.417431 (9aea000394714d2fbb20850021f6204f2256b9cf),platform=Windows NT 6.2.9200 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 86 milliseconds
Build info: version: 'unknown', revision: '1969d75', time: '2016-10-18 09:43:45 -0700'
System info: host: 'Bishnu', ip: '192.168.0.107', os.name: 'Windows 8', os.arch: 'amd64', os.version: '6.2', java.version: '1.8.0_111'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.24.417431 (9aea000394714d2fbb20850021f6204f2256b9cf), userDataDir=C:\Users\Bishnu\AppData\Local\Temp\scoped_dir11044_5076}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=54.0.2840.99, platform=WIN8, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 505ec9fb429bc6b9806edb52d75856f0
    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.ErrorHandler.createThrowable(ErrorHandler.java:216)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:635)
    at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:274)
    at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:84)
    at in.prolearn.pages.HomePage.SecondCapacitySelection(HomePage.java:59)
    at in.prolearn.testcases.VerifySnapDealSelection.main(VerifySnapDealSelection.java:22)

感谢。

3 个答案:

答案 0 :(得分:0)

您可以使用JavaScript吗

        WebElement product = new WebDriverWait(aDriverInstance, 5L).
                until(ExpectedConditions.visibilityOfElementLocatedBy(By.id("anID")));

        JavascriptExecutor jsExec = (JavascriptExecutor) aDriverInstance;
        jsExec.executeScript("arguments[0].scrollIntoView()", product);

答案 1 :(得分:0)

Actions actions = new Actions(driver);
actions.moveToElement(select).click().perform();

尝试使用Actions类单击该元素。这对你有帮助。

答案 2 :(得分:0)

在点击该元素之前使用.isSelected()方法。