Selenium: Difference between revisions

From Network Security Wiki
Content added Content deleted
No edit summary
No edit summary
Line 2:
__TOC__
<br />
 
= Installation =
 
Install Selenium
Line 15 ⟶ 17:
cp geckodriver /usr/local/bin/
 
= Sample Code =
 
<syntaxhighlight lang="python">
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
import json
 
# When using Self Signed Certificates
profile = webdriver.FirefoxProfile()
profile.accept_untrusted_certs = True
Line 26 ⟶ 28:
options = Options()
options.binary_location = r"/usr/bin/firefox"
options.add_argument("--headless") # if running on a Server with no UI
 
browser = webdriver.Firefox(options=options, firefox_profile=profile, executable_path="/home/ubuntu/geckodriver")
browser.get('https://testsite.com/')
 
driverbrowser.close()
</syntaxhighlight>
 

Revision as of 22:20, 2 March 2021


Installation

Install Selenium

pip3 install selenium

Install Firefox: sudo apt install firefox

Install geckodriver:

Download latest geckodriver from github.com
wget https://github.com/mozilla/geckodriver/releases/download/v0.29.0/geckodriver-v0.29.0-linux64.tar.gz
tar -xf geckodriver-v0.29.0-linux64.tar.gz
cp geckodriver /usr/local/bin/

Sample Code

from selenium import webdriver
from selenium.webdriver.firefox.options import Options

# When using Self Signed Certificates
profile = webdriver.FirefoxProfile()
profile.accept_untrusted_certs = True

options = Options()
options.binary_location = r"/usr/bin/firefox"
options.add_argument("--headless")           # if running on a Server with no UI

browser = webdriver.Firefox(options=options, firefox_profile=profile, executable_path="/home/ubuntu/geckodriver")
browser.get('https://testsite.com/')

browser.close()



References





{{#widget:DISQUS |id=networkm |uniqid=Selenium |url=https://aman.awiki.org/wiki/Selenium }}