0

I am trying to use Selenium with Python to click on a text field, which opens a pop-up panel, select the text entry area of that popup, and enter text to it.

switch_to_window and switch_to_frame don't seem to be working. In a previous question I asked about Selenium, someone told me to pause the program until the element I need is available. The solution worked for that problem, but not this one, so I'm assuming I have a different issue and I'm too new to Selenium to understand what it is.

This is what the original box I'm trying to click on looks like:

enter image description here

And the Inspect Element for this box:

enter image description here

When that description box is clicked, it should open this window:

enter image description here

And select this element to enter text into:

enter image description here

So in my code I have:

descriptionBox = driver.find_element_by_id('kiadvany_fulszoveg_text')
descriptionBox.click()

That does not error the program, but it also doesn't seem to actually be clicking on that element. To make matters more confusing, I got this to work exactly ONCE, where it opened the correct Description text box as pictured above, but it has since not worked at all even when I try the exact same thing.

The panel's ID is:

enter image description here

As I mentioned, switching to this panel ID using switch_to_frame or switch_to_window was the first thing I tried, but I'm getting a No Such Element error.

Because I saw the description box open correctly once, but never again, I'm assuming that's where the problem is. I wish, the one time it did pop up, that I'd tried to put the text into the field to see if that would work too, but I hadn't gotten there yet at that point, so I don't know if that would have worked.

Thank you in advance to anyone who can help with this!

7
  • switch_to_window is only used for switching to another browser window, which does not seem to be your case. switch_to_frame is only used for switching to an iframe element on the page - if you don't have iframes on that page - that its not you case as well. Most likely there is something tricky related to JavaScript that gets triggered when you click description area manually vs clicking it with Selenium. Commented Jun 20, 2017 at 18:01
  • All i can think of right now is check the event listeners on that description html element using Google Chrome tool and see which listeners triggers the popup. Commented Jun 20, 2017 at 18:02
  • One more idea comes to head: try clicking that element with JavaScript and see what happens. Commented Jun 20, 2017 at 18:02
  • I'm sorry, I'm in the dark when it comes to javascript. What tool do I use to look at event listeners and try clicking with javascript? Thank you for your answers though! Commented Jun 20, 2017 at 18:27
  • You can execute a piece of JavaScript using Selenium JavaScriptExecutor like following: driver.execute_script("document.getElementsByClassName('comment-user')[0].click()") Commented Jun 20, 2017 at 18:35

1 Answer 1

1

Try this

 descriptionBox = driver.find_element_by_id('kiadvany_fulszoveg_text')
 driver.execute_script('arguments[0].click();', descriptionBox)

or

actions = ActionChains(driver)
actions.move_to_element(descriptionBox)
actions.click(descriptionBox)
actions.perform()
Sign up to request clarification or add additional context in comments.

6 Comments

Your first solution got the description box to open, finally, thank you!! I still can't get it to actually click the description field within that window and enter the text, though. I have tried both id=mceu_43, which highlights the text area when I inspect it, and id=rteTA because it's called "text area" in the picture I included above and I figured that made sense. Both give me Element Not Visible exceptions. I'm sorry to be a bother, but do you have any fancy solutions that could select that field and enter text? Thank you in advance!
Glad it worked for you. Any reason why you want to click on the textarea on the popup and then enter text on it. Since it's a text area, can you wait till it's loaded after the descriptionbox is clicked, and enter text.
and you are able to locate it on the dom, you should be able to find it and enter text.
Yes, for some reason when the popup opens, the text area is not already selected. Entering text does nothing. I have to manually click to get a cursor before I can start typing. So I'd have to do the same thing with the code somehow. Using those IDs still results in Element Not Visible. The setup of this website baffles me.
I can make a separate question for this, if you don't have an answer. I really appreciate the help with the last part!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.