Changes

Jump to navigation Jump to search
1,419 bytes added ,  17:03, 21 December 2017
no edit summary
For example, the following could be used to scroll to the bottom of the page:
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
 
===Clicking===
If an element is clickable (such as a link or a button), you can click on that element by doing:
element.click()
 
This will route you to the linked page, or execute the action of the button. The driver will now be on the new page, and commands will deal with elements on the new page.
 
===Open a New Window===
OPTION 1: Cntrl + Click
-----------------------
 
This method will utilize Action Chains and Keys. Action Chains simply queue commands, and the string of commands are executed once the perform() method is called. First, import these dependencies:
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
 
OPTION 2: Open Blank Window + get()
-----------------------------------
 
===Downloading Files===
In general, I recommend using Selenium to do browsing, and use another method to download the file.
driver.current_url
 
This will get the current url. From there, standard libraries such as wget or urlretrieve can be used to download the file if the url ends in .pdf, or the html of the page if it is a regular webpage.
 
If you are trying to retrieve a body of text, find the element using selectors. Then:
element.text
 
will retrieve the text in that element as a string. This can then be written to a file in any way you see fit.
 
[http://stackabuse.com/download-files-with-python/ Helpful link for downloading files in python]
 

Navigation menu