如何找到购买按钮的相对xpath

问题描述 投票:0回答:1

我想找到购买按钮的xpath。我使用通过 Chrome 进行复制来创建路径,但它们无法在我需要它们工作的网站的每个页面上工作。 我需要一个路径,以便如果将来网站发生变化,我的 xpath 仍然有效。

<div id="buySellOrder" class="valign-wrapper vspace-between width100 buySellOrder_bso21Parent__8UIa8">
    <div class="valign-wrapper vspace-between buySellOrder_bso21Main__KhLIN width100">
        <div class="width100 buySellOrder_bso21Lower__WiRcn absolute-center">
            <div class="width100">
                <div class="">
                    <div class="btn96DefaultClass absolute-center cur-po bodyBaseHeavy contentPrimary cur-po btn96MediumButton btn86FullWidth btn96ButtonLabel contentOnColour backgroundAccent btn96ButtonHover"><span class="">BUY</span></div>
                </div>
            </div>
        </div>
    </div>
</div>

我尝试了以下路径,但它们不起作用:

//*[contains(@class,"btn96ButtonLabel") and contains(@class,"contentOnColour") and contains(@class,"backgroundAccent") and contains(@class,"btn96ButtonHover") and .//span[contains(text(), "BUY")]

//*[@id="buySellOrder"][contains(@class,"btn96ButtonLabel") and contains(@class,"contentOnColour") and contains(@class,"backgroundAccent") and contains(@class,"btn96ButtonHover") and .//span[contains(text(), "BUY")]

javascript html dom xpath css-selectors
1个回答
0
投票

要使用 XPath 正确选择“购买”按钮,可以使用以下表达式:

//div[@id="buySellOrder"]//div[contains(@class, "btn96DefaultClass") and contains(@class, "btn96ButtonHover")]//span[contains(text(), "BUY")]
© www.soinside.com 2019 - 2024. All rights reserved.