我正在使用 selenium 和 python 來(lái)學(xué)習(xí)自動(dòng)化 Web 測(cè)試。我想單擊“繼續(xù)”按鈕,雖然其中只有跨度(我了解到使用 id 而不是跨度要容易得多)但在這種情況下,我想單擊跨度。我正在使用以下代碼:driver.find_element_by_xpath("//span[contains(@class,'mdBtn01Txt')][contains(text(),'Continue')]").click()這是元素:<div class="mdLYR12Inner01"><a class="MdBtn01 mdBtn01 ExDisabled FnSubmitBtn" style="display:none" href="#" onclick="charge(this); return false;"><span class="mdBtn01Inner"><span class="mdBtn01Txt">Continue <<<(I want to click this button)</span></span></a> </div></footer>但是,我在下面收到了這條消息:raise exception_class(message, screen, stacktrace)selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//span[contains(@class,'mdBtn01Txt')][contains(text(),'Continue')]"}
1 回答

翻閱古今
TA貢獻(xiàn)1780條經(jīng)驗(yàn) 獲得超5個(gè)贊
看起來(lái)不像一個(gè)有效的 xpath,正確的應(yīng)該是
//span[@class='mdBtn01Txt']
以下是為 XPath 創(chuàng)建 xpath 語(yǔ)法的規(guī)則:
XPath 包含位于網(wǎng)頁(yè)上的元素的路徑。創(chuàng)建 XPath 的標(biāo)準(zhǔn)語(yǔ)法是:
Xpath=//tagname[@attribute='value']
標(biāo)記名:特定節(jié)點(diǎn)的標(biāo)記名。
@:選擇屬性。
屬性:節(jié)點(diǎn)的屬性名稱(chēng)。
值:屬性的值。
添加回答
舉報(bào)
0/150
提交
取消