Python Forum
Looping actions in an iframe using Selenium on Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Looping actions in an iframe using Selenium on Python
#1
First of all, I would like to say I am very new to Python and web-scraping so I apologise if I am missing something quite obvious. I am trying to webscrape an iframe object containing a list of links. The ultimate objective is to perform a series of actions, which is the same for each link, that leads to downloading some data in xls format.

For each of the links in the iframe, I want to automate the following actions: 1. click on the link 2.select from a drop down list the option for getting data since 1999 3.click on the excel download button.

My code works for the first one of the links, but I am struggling with automating it to go through all the links in the iframe.

This is the code that works for the first link:

#this automates the log in
driver.find_element_by_id('user').send_keys('myusername')
driver.find_element_by_id('password').send_keys('mypassword')
driver.find_element_by_xpath('myxpath').click()

#this switches to iframe and clicks on all the links 
driver.switch_to.frame("report-iframe")
driver.find_element_by_tag_name('a').click()

#this performs the required actions for the first link(select drop down, select excel download)  
s= Select(driver.find_element_by_id('start-date'))
s.select_by_value('1999-01-01')

driver.find_element_by_xpath('//*[@id="report-excel-download"]')

wait = WebDriverWait(driver, 10)
element = wait.until(EC.element_to_be_clickable((By.ID, 'report-excel-download')))
element.click()
I want to automate this process for all the links in the iframe (i.e. for each of the links in iframe, click on the link, select the drop down, click the data download button. Does anyone have any advice in how to do this?

Thanks!
Reply
#2
please supply URL
Reply
#3
(Mar-06-2019, 08:13 PM)Larz60+ Wrote: please supply URL
The URL requires a paid subscription so you wouldn't be able to access it, which is why I did not include it in the original post-there are also some security concerns with sharing the URL. I guess any general advice on how to implement such a loop would be useful!
Reply
#4
It's very difficult to analyze what's needed if we can't see the page contents.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How do I iterate over an array and perform actions using selenium chrome webdriver? master 0 2,387 Sep-14-2020, 05:28 AM
Last Post: master
  selenium click in iframe fails 3Pinter 6 5,025 Apr-29-2020, 12:59 PM
Last Post: Larz60+
  Extracting Text in a canvas using chain actions law 3 2,266 Apr-22-2020, 11:45 AM
Last Post: Larz60+
  How to find which frame/iframe my element belongs to? smaria 1 2,034 Nov-18-2019, 09:21 PM
Last Post: Larz60+
  Python Looping dnetvaggos 3 69,830 Dec-08-2018, 11:20 AM
Last Post: Larz60+
  scraping with multiple iframe jansky 1 4,166 Nov-09-2018, 11:12 AM
Last Post: snippsat
  Looping problem using Selenium smk90 0 2,235 Sep-19-2018, 08:48 PM
Last Post: smk90
  Unable to select iframe using selenium endejoli 1 2,941 Jan-11-2018, 05:13 PM
Last Post: j.crater
  Error in Selenium: CRITICAL:root:Selenium module is not installed...Exiting program. AcszE 1 3,587 Nov-03-2017, 08:41 PM
Last Post: metulburr
  Unable to print data while looping through list in csv for webscraping - Python Prince_Bhatia 1 3,476 Oct-04-2017, 11:18 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020