1

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', "user@user.com")
password = doc.findfirst("input[id=pass]")
bt.evaluateJavaScript('this.click()')

#this one after getting button element as above ones

Mohamed Yousof
  • 725
  • 1
  • 9
  • 38

2 Answers2

1

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.

Community
  • 1
  • 1
Matanoga
  • 101
  • 5
  • 2
    Thanks for your reply, but setattribute is working for me , what i am asking about is : when i get the element is to click it , for example the text area in facebook group i can find it but got error when trying to click it so it opened and the button "Post" appears – Mohamed Yousof Sep 08 '14 at 15:23
  • Oh, I think what you're trying to do is "focus" the element then. I'll edit my answer. – Matanoga Sep 09 '14 at 07:56
0

for focusing text area element like "facebook group text area" use "txtarea.evaluateJavaScript("this.focus()") instead of "this.click()" this worked for me

Mohamed Yousof
  • 725
  • 1
  • 9
  • 38