python selenium如何操作js的确认框-如图?

js代码如下,点击按钮时javascript:void(0);,不能直接点击,也不能用alert获取,有没有大佬知道如何操作js点击确认按钮。var ConfirmPopup = new Class({ _popup: null, _question: null, _caution: null, _yes: null, _onOkFunc: function() { alert("ok") }, initialize: function(i) { this._popup = new Element("div"), this._popup.className = "minimumPopup"; var t = new Element("p"); t.className = "cautionMessage", this._question = new Element("span"), this._question.className = "iconAttention", this._question.innerHTML = "削除しますか?", t.appendChild(this._question); var e = new Element("p"); e.className = "cautionMessage2", this._caution = new Element("span"), e.appendChild(this._caution); var n = new Element("p"); n.className = "minimumApplyButton", this._yes = new Element("a"); var s = new Element("a"); this._yes.href = s.href = "javascript:void(0);", this._yes.innerHTML = "はい", s.innerHTML = "いいえ", this._yes.onclick = this.ok.bindAsEventListener(this), s.onclick = this.cancel.bindAsEventListener(this), n.appendChild(this._yes), n.appendChild(s), this._popup.appendChild(t), this._popup.appendChild(e), this._popup.appendChild(n), this._popup.style.visibility = "hidden", document.body.appendChild(this._popup), i || (i = 100), this.setZindex(i) }, ok: function(i) { this._onOkFunc(), this.hide(), new Event(i).stop() }, cancel: function(i) { this.hide(), new Event(i).stop() }, show: function(i, t, e, n) { e && (this._question.innerHTML = e), n ? (this._caution.innerHTML = n, this._caution.parentNode.style.display = "block") : this._caution.parentNode.style.display = "none", i && (this._onOkFunc = i); var s = this.cumulativeOffset(t); this._popup.style.left = s.x - this._popup.offsetWidth / 2 + t.offsetWidth / 2 + 3 + "px", this._popup.style.top = s.y - this._popup.offsetHeight - 8 + "px", this._popup.style.visibility = "visible" }, hide: function() { this._popup.style.visibility = "hidden" }, setZindex: function(i) { this._popup.style.zIndex = i }, cumulativeOffset: function(i) { for (var t = 0, e = 0; t += i.offsetTop || 0, e += i.offsetLeft || 0, i = i.offsetParent; ) ; return { x: e, y: t } }});

第1个回答  2019-12-19
你试试select可不可以,下面是示例

from selenium import webdriver
from selenium.webdriver.support.ui import Select

browser = webdriver.Firefox()
url = ' '
browser.get(url=url)

select_tag = browser.find_element_by_css_selector(' ')
select_btn = Select(select_tag)
select_btn.select_by_visible_text('输入选择的文字')
select_btn.deselect_all()
相似回答