简体   繁体   English

在Selenium Webdriver中找不到Web应用程序的元素

[英]Not able to find element of a web application in selenium webdriver

I am trying to click a button using selenium webdriver 我正在尝试使用Selenium WebDriver单击按钮

driver.findElement(By.xpath(".//*[@id='addLog']")).click();

But am getting an error 但是出现错误

org.openqa.selenium.WebDriverException: unknown error: Element <button id="addLog" type="button" class="btn btn-awh1" onclick="addLog()">...</button> is not clickable at point (516, 209). Other element would receive the click: <div id="BBOverlay" style="opacity: 0.216303; width: 1034px; height: 506px;"></div>

HTML: HTML:

<!-- Operation Button -->
<div class="row">
    <div class="col-md-12">
        <div class="form-group">
            <div class="col-md-4" />
            <div class="col-md-4" style="text-align: center;">
                <div class="btn-group">
                    <button id="addLog" class="btn btn-awh1" type="button"     onclick="addLog()">
                    Create My Health Log
                      <i class="fa fa-plus" aria-hidden="true"/>
                    </button>
                </div>
            </div>
            <div class="col-md-4" />
        </div>
    </div>
    <!-- End Of Operation Button -->
</div>

The code before this operation button is 该操作按钮之前的代码是

  <!-- Nav tabs -->
    <ul class="nav nav-tabs" role="tablist">
    <li class="active" role="presentation">
    <a href="#log" aria-controls="log" role="tab" data-toggle="tab">My Health Log</a>
    </li>
    <li role="presentation">
    <a href="#details" aria-controls="details" role="tab" data-toggle="tab">My Health Details</a>
    </li>
    <li role="presentation">
    <li role="presentation">
    </ul>
    <!-- Tab panes -->
    <div class="tab-content" style="margin-top:25px">
    <!-- My Health Log -->
    <div id="log" class="tab-pane active center" role="tabpanel">

Any help is appreciated. 任何帮助表示赞赏。

If you read the error message, it states that there is an element covering the element you are trying to click. 如果您阅读该错误消息,则表明存在一个试图覆盖您要单击的元素的元素。 I'm not sure what the element is 我不确定元素是什么

<div id="BBOverlay" style="opacity: 0.216303; width: 1034px; height: 506px;"></div>

but from the id it looks like it's an overlay of some sort. 但从ID来看,它看起来像是某种覆盖物。 I would wait for that element to be invisible and then click the desired button. 我将等待该元素不可见,然后单击所需的按钮。 I can't know if that will work for sure given the info you've provided so you'll have to try it and let me know. 鉴于您提供的信息,我不确定这是否行得通,因此您必须尝试一下并让我知道。

new WebDriverWait(driver, 10).until(ExpectedConditions.invisibilityOfElementLocated(By.id("BBOverlay")));
driver.findElement(By.id("addLog")).click();

Try the following xpath if it works for you: 如果适合您,请尝试以下xpath

driver.findElement(By.xpath("//button[contains(text(),'Create My Health Log')]")).click();

OR 要么

driver.findElement(By.xpath("//button[@class='btn btn-awh1']")).click();

OR 要么

driver.findElement(By.xpath("//button[@id='addLog'][@class='btn btn-awh1']")).click();

OR 要么

driver.findElement(By.cssSelector(".btn-group #addLog")).click();

OR 要么

driver.findElement(By.cssSelector(".row .form-group .col-md-4 .btn-group #addLog")).click();

I guess the element is below in page and you need to scroll for it: This will work I guess 我猜元素在页面下方,您需要滚动一下:我猜这可以工作

WebElement elements = driver.findElement(By.xpath("//button[@class='btn btn-awh1']"))   
Thread.sleep(3000L);
JavascriptExecutor js = (JavascriptExecutor) driver;
int yPosition = elements.getLocation().getY();
js.executeScript("window.scroll (0, " + yPosition + ") ");
Thread.sleep(3000L);
driver.findElement(By.xpath("//button[@class='btn btn-awh1']")).click();

Let me know if any of them works for you. 让我知道其中是否有一项适合您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM