无法点击类div SELENIUM

时间:2015-10-23 02:34:03

标签: java selenium automation

我无法点击该元素。我能够使用xpath找到它,带有语句的对象" element.getText()"返回正确的值" element.isDisplayed()"返回true但是当我说" element.click()"它没有点击就跳过动作。请告知我的错误。谢谢你

代码按钮:

public static WebElement btn_AddDoubleBet(WebDriver driver) throws Exception{
        try{ 
             driver.manage().timeouts().implicitlyWait(70, TimeUnit.SECONDS);
             //element = driver.findElement(By.cssSelector("html.js.flexbox.flexboxlegacy.canvas.canvastext.webgl.no-touch.geolocation.postmessage.no-websqldatabase.indexeddb.hashchange.history.draganddrop.websockets.rgba.hsla.multiplebgs.backgroundsize.borderimage.borderradius.boxshadow.textshadow.opacity.cssanimations.csscolumns.cssgradients.no-cssreflections.csstransforms.csstransforms3d.csstransitions.fontface.generatedcontent.video.audio.localstorage.sessionstorage.webworkers.applicationcache.svg.inlinesvg.smil.svgclippaths body div.wrap div#game.content.fr div.main.fl div#lottery.lottery div.count span.times span div.number-spin-btn.number-spin-btn-up"));
             element = driver.findElement(By.xpath("/html/body/div[2]/div[2]/div[1]/div[2]/div[4]/span[2]/span/div[2]"));
             Log.info("Increase Betting");
        }catch (Exception e){
            Log.error("Increase Betting is not found on the Confirmation Page");
            throw(e);
            }
        return element;
    }

产品选择代码:

public static void BigSmallOddEven_Back_Execute(WebDriver driver)
            throws Exception {

        BigSmallOddEven_Page.btn_BigSmallOddEven(driver).click();

        for (int i = 0; i < 3; i++) {
            ConfirmationPlaceBet_Page.btn_AddDoubleBet(driver).click();
        }
        BigSmallOddEven_Page.pick_SelectedBigSmallOddEven(driver, 1).click();
        BigSmallOddEven_Page.pick_SelectedBigSmallOddEven(driver, 7).click();



        ConfirmationPlaceBet_Page.btn_ConfirmNumberToBet(driver).click();

        for (int k = 0; k < 49; k++) {
            ConfirmationPlaceBet_Page.btn_IncreaseBet(driver).click();
        }

        ConfirmationPlaceBet_Page.btn_ProceedBet(driver).click();

        ConfirmationPlaceBet_Page.btn_ConfirmBet(driver).click();
    }

HTML CODE:

<div class="number-spin-btn number-spin-btn-up" style="height: 21px"></div>

1 个答案:

答案 0 :(得分:2)

我认为正在点击WebElement。但是点击的WebElement不是你想要的元素。

从您提供的HTML代码中,尝试

driver.findElement(By.cssSelector("div.number-spin-btn.number-spin-btn-up")).click();

如果没有其他WebElements具有相同的CSS选择器,那么这绝对应该单击您的WebElement。

您可能还希望在单击元素后在for循环中添加一些等待时间。因为你需要给页面一些时间来对你的输入做出反应。