Selenium: Difference between revisions
Content added Content deleted
(Created page with "Category:Scripting __TOC__ <br /> <br /> ;References <references/> <br /> <br /> <br /> {{DISQUS}}") |
|||
(6 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
<br /> |
<br /> |
||
= Installation = |
|||
Install Selenium |
|||
pip3 install selenium |
|||
Install Firefox: |
|||
sudo apt install firefox |
|||
Install geckodriver: |
|||
Download latest geckodriver from [https://github.com/mozilla/geckodriver/releases 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/ |
|||
export GECKO_DRIVER_VERSION='v0.29.0' |
|||
= Using Self Signed Certificates = |
|||
<syntaxhighlight lang="python"> |
|||
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() |
|||
</syntaxhighlight> |
|||
= Testing reachability = |
|||
<syntaxhighlight lang="python"> |
|||
#!/usr/bin/env python |
|||
import unittest |
|||
from selenium import webdriver |
|||
from selenium.webdriver.firefox.options import Options |
|||
class TestUbuntuHomepage(unittest.TestCase): |
|||
def setUp(self): |
|||
options = Options() |
|||
options.add_argument("--headless") |
|||
self.browser = webdriver.Firefox(options=options) |
|||
def testTitle(self): |
|||
self.browser.get('http://www.ubuntu.com/') |
|||
self.assertIn('Ubuntu', self.browser.title) |
|||
def tearDown(self): |
|||
self.browser.quit() |
|||
if __name__ == '__main__': |
|||
unittest.main(verbosity=2) |
|||
</syntaxhighlight> |
|||
Latest revision as of 23:24, 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/ export GECKO_DRIVER_VERSION='v0.29.0'
Using Self Signed Certificates
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()
Testing reachability
#!/usr/bin/env python
import unittest
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
class TestUbuntuHomepage(unittest.TestCase):
def setUp(self):
options = Options()
options.add_argument("--headless")
self.browser = webdriver.Firefox(options=options)
def testTitle(self):
self.browser.get('http://www.ubuntu.com/')
self.assertIn('Ubuntu', self.browser.title)
def tearDown(self):
self.browser.quit()
if __name__ == '__main__':
unittest.main(verbosity=2)
- References
{{#widget:DISQUS
|id=networkm
|uniqid=Selenium
|url=https://aman.awiki.org/wiki/Selenium
}}