Reputation: 775
I am using QWebView with python to create an automate application and I could select Qwebelements by tags and id, also it's easy to click buttons but I can't do the following - click elements with tag "Textarea" to prepare them to insert data - send keys to textrea elements
the code example for what I can do to fill a form is below but it doesn't work for textarea elements
page = webview.page().mainFrame()
doc = page.documentElement()
username = doc.findFirst("input[id=email]")
username.setAttribute('value', "[email protected]")
password = doc.findfirst("input[id=pass]")
bt.evaluateJavaScript('this.click()')
#this one after getting button element as above ones
Upvotes: 1
Views: 609
Reputation: 101
Element focusing:
You're trying to 'focus' an element, meaning that input goes to that element. to focus, just try this:
txtarea = self.documentElement.findFirst('textarea[name="someTextArea"]')
txtarea.evaluateJavascript('this.focus()')
Setting Attributes vs Properties: The most straightforward way to do this is just set the value of the 'textarea' using JavaScript (instead of setting the attribute directly).
Example:
txtarea = self.documentElement.findFirst('textarea[name="someTextArea"]')
txtarea.evaluateJavaScript('this.value="' + yourText + '";')
Some extra details:
The reason 'setAttribute' didn't work for you: you're trying to change the Attribute called 'value', whereas what you should actually change is the Property 'value'. the difference between the two is explained here.
Upvotes: 1
Reputation: 775
for focusing text area element like "facebook group text area" use "txtarea.evaluateJavaScript("this.focus()") instead of "this.click()" this worked for me
Upvotes: 0