简体   繁体   English

硒找不到该元素

[英]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. 我试图通过以下两种方法单击网站上的元素:ID,Relative和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. 这些方法中的每一种都会失败,因为该页面的HTML被设置为单个页面应用程序,并且其中有多个具有相同ID的按钮,等等。我想知道如何才能解决此问题,以便能够单击因为Selenium很难区分几个类似的按钮。

Here is some HTML for the element: 这是元素的一些HTML:

<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" 我尝试选择的按钮是id="wotc-button"

Relative XPath: .//*[@id='wotc-button'] 相对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 绝对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))); }

听起来您只需要“活动页面”中的一个按钮即可:

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

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

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