lmcphers
lmcphers

Reputation: 468

Selenium can't locate this element

I am trying to click on an element on a Web site by a couple of methods: ID, Relative, and Absolute XPath. Each of these methods fail because the HTML for the page is set up as a single page application and there are several of these buttons with the same ID, etc. I am wondering what I can do to get around this to be able to click the button since Selenium is having a hard time differentiating between the several similar buttons.

Here is some HTML for the element:

<div id="page-15" class="page active-page" style="position: absolute; left: 0px;">
    <div class="main-page">
        <div class="content-page">
            <div class="head"></div>
            <div class="page-body" style="background: none repeat scroll 0% 0% rgb(244, 244, 244);"></div>
            <div class="bottom">
                <button id="wotc-button" class="form-right wotc-button wotc-button-ja ui-button ui-widget ui…ate-default ui-corner-all ui-button-text-only ui-state-focus" role="button" name="wotc-button" aria-disabled="false"></button>
            </div>
        </div>
    </div>
</div>

</div>

The button I am trying to select is the one with id="wotc-button"

Relative XPath: .//*[@id='wotc-button']

Absolute XPath: html/body/div[3]/div/div[3]/div/div/div[2]/div/div[1]/div[17]/div/div/div/div[2]/div/form/div/table/tbody/tr/td/table/tbody/tr/td/div[2]/label

The methods that I'm using to find this element is:

public static WebElement waitFindById(String id) { return wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(id))); }

public static WebElement waitFindByXpath(String xpath) { return wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpath))); }

Upvotes: 1

Views: 178

Answers (1)

alecxe
alecxe

Reputation: 473803

It sounds like you need a button in an "active page" only:

By.cssSelector("div.active-page button#wotc-button")

Upvotes: 1

Related Questions