emptythevoid

seleniumstuff

Apr 25th, 2022
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. # Here is how I'm scrolling the page down
  2. # There are two ways to handle this - you can work on the accounts as you go,
  3. # or you can grab all the unique account names first, as a list, and then process them.
  4. # Either way, you'll have to decide how far you want to scroll into past transactions.
  5.  
  6. elem = driver.find_element_by_xpath("/html/body")
  7. elem.send_keys(Keys.PAGE_DOWN)
  8. time.sleep(3) # because it takes a moment to load
  9.  
  10. # You requested specifically that you wanted to open the accounts in a new tab
  11. # This means you can't simply .click() on the elements. You have to grab the href
  12. # from each one first and process it. Here is one possible way to do that
  13.  
  14. # from the current scroll view, look at all the rows and grab the href from all the To accounts
  15. # keep in mind that the accounts in this list will not be unique - there will be duplicates!
  16. # You will need to put this in some kind of loop so that you can send a page down or a scroll,
  17. # get more accounts, process them, then scroll some more
  18. my_list = driver.find_elements_by_xpath('//div[@role="listitem"]/button/div/div[6]/div/a')
  19.  
  20.  
  21. # Now that we have the list of hrefs, what should we do with them
  22. # here is a function that will open each one in a new tab
  23. # Keep in mind that this function uses a *list* of hrefs and loops over them
  24. # If you wanted to use this as you went along, you should still be able to use
  25. # the tab opening logic
  26. def open_accounts(driver, my_list):
  27. for account in my_list:
  28.  
  29. # open a new browser tab
  30. driver.execute_script("window.open('');")
  31.  
  32. # switch selenium to focus on the new tab
  33. # if your program has other tabs open besides the search results
  34. # adjust the window_handles[] accordingly
  35. driver.switch_to.window(driver.window_handles[1])
  36.  
  37. # open an href
  38. driver.get(account)
  39.  
  40. #
  41. # here is where you need to put whatever it is you're doing with these account pages
  42. #
  43. #
  44.  
  45. # close the tab when done
  46. driver.close()
  47.  
  48. # switch selenium focus back to the search page
  49. driver.switch_to.window(driver.window_handles[0])
Advertisement
Add Comment
Please, Sign In to add comment