我有如下所示的 html:
<div class=someclass>some text here</div>
我可以用 selenium 在上面的 html 中插入另一個 div 嗎?我試過用 js 命令執行這個,但是沒有用,因為頁面上有很多 div,它們具有相同的類,所以我使用 xpath 找到我想要的 div
uj5u.com熱心網友回復:
你有沒有嘗試過這樣的事情?
js = """var node = document.createElement("div");
var textnode = document.createTextNode("Example");
node.appendChild(textnode);
document.getElementById("someIDOnPage").appendChild(node);
"""
driver.execute_script(js)
如果您有具有相同類名的 div,只需使用不同的 ID。你也可以像這樣用 JS 做到這一點:
g = document.createElement('div');
g.setAttribute("id", "Div1");
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/367172.html
上一篇:mips:在堆中存盤字串的功能
