Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Here is how I'm scrolling the page down
- # There are two ways to handle this - you can work on the accounts as you go,
- # or you can grab all the unique account names first, as a list, and then process them.
- # Either way, you'll have to decide how far you want to scroll into past transactions.
- elem = driver.find_element_by_xpath("/html/body")
- elem.send_keys(Keys.PAGE_DOWN)
- time.sleep(3) # because it takes a moment to load
- # You requested specifically that you wanted to open the accounts in a new tab
- # This means you can't simply .click() on the elements. You have to grab the href
- # from each one first and process it. Here is one possible way to do that
- # from the current scroll view, look at all the rows and grab the href from all the To accounts
- # keep in mind that the accounts in this list will not be unique - there will be duplicates!
- # You will need to put this in some kind of loop so that you can send a page down or a scroll,
- # get more accounts, process them, then scroll some more
- my_list = driver.find_elements_by_xpath('//div[@role="listitem"]/button/div/div[6]/div/a')
- # Now that we have the list of hrefs, what should we do with them
- # here is a function that will open each one in a new tab
- # Keep in mind that this function uses a *list* of hrefs and loops over them
- # If you wanted to use this as you went along, you should still be able to use
- # the tab opening logic
- def open_accounts(driver, my_list):
- for account in my_list:
- # open a new browser tab
- driver.execute_script("window.open('');")
- # switch selenium to focus on the new tab
- # if your program has other tabs open besides the search results
- # adjust the window_handles[] accordingly
- driver.switch_to.window(driver.window_handles[1])
- # open an href
- driver.get(account)
- #
- # here is where you need to put whatever it is you're doing with these account pages
- #
- #
- # close the tab when done
- driver.close()
- # switch selenium focus back to the search page
- driver.switch_to.window(driver.window_handles[0])
Advertisement
Add Comment
Please, Sign In to add comment