我正嘗試在QwebView瀏覽器中使用javascript顯示選定的文本。但我不知道爲什麼它不工作.. 這裏是我的代碼: -在Qwebview中使用javascript顯示選定的文本
frame = self.page().mainFrame().documentElement()
frame.evaluateJavaScript("alert("+"'"+frame.getSelection().toString()+"'"+");")
當我運行這段代碼就說明我的錯誤: -
Traceback (most recent call last):
File "GUI-Test.py", line 32, in slotshowxpath
frame.evaluateJavaScript("alert("+"'"+frame.getSelection().toString()+"'"+");")
AttributeError: 'QWebElement' object has no attribute 'getSelection'
我知道,但我想知道如何獲得使用JavaScript的選定元素。我也知道我們可以使用self.selectedText獲取文本,但是我正在尋找元素。 –
@rickyrana,'frame.evaluateJavaScript(「alert(window.getSelection()。toString())」)' – 7stud
感謝兄弟,它的工作 –