我正在使用 selenium 和 python 來學習自動化 Web 測試。我想單擊“繼續”按鈕,雖然其中只有跨度(我了解到使用 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貢獻1780條經驗 獲得超5個贊
看起來不像一個有效的 xpath,正確的應該是
//span[@class='mdBtn01Txt']
以下是為 XPath 創建 xpath 語法的規則:
XPath 包含位于網頁上的元素的路徑。創建 XPath 的標準語法是:
Xpath=//tagname[@attribute='value']
標記名:特定節點的標記名。
@:選擇屬性。
屬性:節點的屬性名稱。
值:屬性的值。
添加回答
舉報
0/150
提交
取消