1

I have been trying to understand how switching to a frameset works using py-selenium with no avail.

The website I am stating here is very similar to the web application that I am working on. https://www.quackit.com/html/tutorial/frame_example_frameset_1.html

Ideally I would like to access element-1 in this image and then move to the second frame and access element-2.

image

9
  • 1
    Possible duplicate of selecting an iframe using python selenium Commented Aug 9, 2017 at 16:42
  • Thank you responding Bill Bell. However I am looking at a frameset and not iframe. I am able to move across iframes which python selenium identifies the element as frames. But the tag frameset nor the frame src is identifed as frames. Commented Aug 9, 2017 at 16:50
  • That wasn't me. :) I looked at the HTML and could see that it includes a couple of frame elements. That's why I felt justified in altering the text in your question slightly. Commented Aug 9, 2017 at 17:03
  • Can you describe your issue in more details? Also share the code you've tried along with the exception log (if you get any). Note that you don't need to switch to frameset as frameset is common WebElement and should be handled appropriatelly Commented Aug 9, 2017 at 17:08
  • I am sorry Bill Bell. My bad. This is my first ever question here. And well, I was able to resolve this with some mystery. Previously when I had tried to use find_element_by_xpath to dig the frame, I was not able to, but after a couple of coffees and 2 hours, I was able to get it. :-) Commented Aug 9, 2017 at 17:55

1 Answer 1

2

Here is one approach.

Load the initial page. Use an xpath expression to find the two frame elements. The, for each of them, get its url. Now you can use driver.get again (for each url) to load the page corresponding to the frame, and then find the p element that you want.

>>> from selenium import webdriver
>>> driver = webdriver.Chrome()
>>> driver.get('https://www.quackit.com/html/tutorial/frame_example_frameset_1.html')
>>> for frame in driver.find_elements_by_xpath('.//frame'):
...     frame.get_attribute('src')
...     
'https://www.quackit.com/html/tutorial/frame_example_left.html'
'https://www.quackit.com/html/tutorial/frame_example_right.html'

Any questions, please ask. If this does what you want, please mark the answer 'accepted' since that's the protocol on SO.

Sign up to request clarification or add additional context in comments.

2 Comments

Hey Bill, this worked !!! driver.get("quackit.com/html/tutorial/frame_example_frameset‌​_1.html") frame1=driver.find_element_by_xpath('/html/frameset/frame[1]‌​') driver.switch_to_frame(frame1)
Yup, that was a possibility. I was looking for an answer as simple an answer as possible.

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.