gpt4 book ai didi

selenium - 当按钮 webelement 是动态时如何在 selenium webdriver 中查找 xpath

转载 作者:行者123 更新时间:2023-12-02 12:13:14 27 4
gpt4 key购买 nike

以下是该页面的 html,我需要获取将在 selenium webdriver 中工作的按钮的 xpath。或者有什么方法可以点击 selenium webdriver 中的按钮如果是 java 那就太好了,否则 python 和其他语言也很受欢迎。

<button style="" onclick="saveAndContinueEdit('http://192.168.1.99/cue_extensions/magento1.9/index.php/admin/catalog_product/save/back/edit/tab/{{tab_id}}/id/899/key/6ed7b01b3a2136d6ff896d9380e281d5/')" class="scalable save" type="button" title="Save and Continue Edit" id="**id_636f54090db18b58eecba78e9e6aa6b7**">
<span><span><span>Save and Continue Edit</span></span></span>
</button>

但是当我下次登录时,html 会更改为

<button style="" onclick="saveAndContinueEdit('http://192.168.1.99/cue_extensions/magento1.9/index.php/admin/catalog_product/save/back/edit/tab/{{tab_id}}/id/903/key/29d8597a8ec8f63d9b09addae444d4c0/')" class="scalable save" type="button" title="Save and Continue Edit" id="id_c2fe56a74ef2a166dcf0ae4ed7f8e391">
<span><span><span>Save and Continue Edit</span></span></span>
</button>[![enter image description here][1]][1]

最佳答案

尝试以下操作:

在 Java 中:

driver.findElement(By.Xpath("//span[contains(text(), 'Save and Continue Edit')]")).click();

Python 中:

driver.find_element_by_xpath("//span[contains(text(), 'Save and Continue Edit')]").click()

关于selenium - 当按钮 webelement 是动态时如何在 selenium webdriver 中查找 xpath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32561352/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com