1
votes

I am trying to click on a on card inside a container. I have tried id, class,xpath but it doesn't find it. I unsure on what else to try to be able to get the element.

here is the code of the element I want to click on:

<div class="mtable" id="w-card" status="83" entertainer="1799">
    <div class="mtable-cell wc-gray-dark" id="widget-icon" style="border-color: ">
        <div class="caption"><img src="/images/default_entertainer_image.jpg" class="caption-img"></div>
    </div>
    <div class="mtable-cell wc-white" id="widget-text">
        <div>
            <h6>
                <span id="status-83" class="label label-default ">
                    <span class="entertainer-name">Testing</span>
                    <br>Testing100
                    <br>Last Seen: never
                </span>
            </h6>
        </div>
        <div id="timers">
            <div id="lastChange" class="pull-left"></div>
            <div id="circle" class="pull-right"></div>
        </div>
    </div>
</div>

selenium code:

driver.findElement(By.xpath("//*[@id=\"w-card\"]")).click();

I have run display tests on all of the child elements of the div as well webdriver is finding it but is saying it's not displayed?

4
Is there n error? What is it? Have you considered clicking on one of the child elements? - SiKing
The error message I receive is org.openqa.selenium.ElementNotVisibleException: element not visible - Taylor Gagne
I ran isDisplayed and it returned that it found the element but says it's not being displayed? - Taylor Gagne

4 Answers

1
votes

Use Explicit Wait to wait for element to be clickable.

WebDriverWait driverWait = new WebDriverWait(driver, timeOutInSeconds);
wait.until(ExpectedConditions.elementToBeClickable(By.id("w-card"))).click();
0
votes

Try to use explicit wait

WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("w-card"))).click();

This will wait up to 20 seconds for the element to be visible before clicking on it.

0
votes

I think your Div is not visible. So do few things run a for loop with 3 sec interval for like 10 iterations and inside that check for isDisplayed() condition, does it ever gets displayed. Also if everything fails then try javascript click..thats never recommended but still saves us

0
votes

Maybe there is an iframe, so switch to that frame.

        `driver.switchTo().frame(driver.findElement(by));`