{"flag":true,"single":true,"pageTitle":"Installation & runing Selenium basic example","post":{"id":92,"user_id":"1","slug":"installation-runing-selenium-basic-example-umgl","title":"Installation & runing Selenium basic example","body":"<p><a href=\"https:\/\/selenium-python.readthedocs.io\/\">DOCUMENTATION https:\/\/selenium-python.readthedocs.io\/<\/a><\/p>\r\n<p>&nbsp;<\/p>\r\n<p>1. Install python3 https:\/\/www.python.org\/downloads\/<\/p>\r\n<p>2. Run command in cmd<\/p>\r\n<pre class=\"language-markup\"><code>pip install selenium<\/code><\/pre>\r\n<p>3. download drivers <strong>https:\/\/sites.google.com\/chromium.org\/driver\/ <\/strong>and paste them in <strong>c:\/\/chromedriver\/*.exe<\/strong><\/p>\r\n<p>4. create script in any loacation ie test.py<\/p>\r\n<pre class=\"language-markup\"><code>from selenium import webdriver\r\nfrom selenium.webdriver.common.keys import Keys\r\nfrom selenium.webdriver.common.by import By\r\nfrom selenium.webdriver.chrome.service import Service\r\n\r\nservice = Service(executable_path=\"C:\\\\chromedriver\\\\chromedriver.exe\")\r\noptions = webdriver.ChromeOptions()\r\ndriver = webdriver.Chrome(service=service, options=options)\r\ndriver.get(\"http:\/\/www.python.org\")\r\nassert \"Python\" in driver.title\r\nelem = driver.find_element(By.NAME, \"q\")\r\nelem.clear()\r\nelem.send_keys(\"pycon\")\r\nelem.send_keys(Keys.RETURN)\r\nassert \"No results found.\" not in driver.page_source\r\ndriver.close()\r\n\r\ndriver.quit()\r\n<\/code><\/pre>\r\n<p>Run the script<\/p>\r\n<pre class=\"language-markup\"><code>py test.py<\/code><\/pre>\r\n<p>&nbsp;<\/p>\r\n<p>FOR STEP 3 NOW Good approach is&nbsp;<\/p>\r\n<pre class=\"language-markup\"><code>pip install webdriver-manager<\/code><\/pre>\r\n<p><strong>Chrome:<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>from selenium import webdriver\r\nfrom selenium.webdriver.chrome.service import Service as ChromeService\r\nfrom webdriver_manager.chrome import ChromeDriverManager\r\ndriver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))<\/code><\/pre>\r\n<p><strong>Edge:<\/strong><\/p>\r\n<pre class=\"language-markup\"><code># selenium 4\r\nfrom selenium import webdriver\r\nfrom selenium.webdriver.edge.service import Service as EdgeService\r\nfrom webdriver_manager.microsoft import EdgeChromiumDriverManager\r\ndriver = webdriver.Edge(service=EdgeService(EdgeChromiumDriverManager().install()))<\/code><\/pre>\r\n<p>ref: <a href=\"https:\/\/pypi.org\/project\/webdriver-manager\/\">https:\/\/pypi.org\/project\/webdriver-manager\/<\/a><\/p>\r\n<p>&nbsp;<\/p>\r\n<p>&nbsp;<\/p>\r\n<p><strong>COMPLETE EXAMPLE:<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>pip install selenium\r\npip install webdriver-manager<\/code><\/pre>\r\n<pre class=\"language-markup\"><code>from selenium import webdriver\r\nfrom selenium.webdriver.common.keys import Keys\r\nfrom selenium.webdriver.common.by import By\r\nfrom selenium.webdriver.chrome.service import Service\r\nfrom selenium.webdriver.chrome.service import Service as ChromeService\r\nfrom webdriver_manager.chrome import ChromeDriverManager\r\nimport os\r\nimport json\r\nimport uuid\r\nimport time\r\nclass Init:\r\n  def __init__(self):\r\n    options = webdriver.ChromeOptions()\r\n    options.add_experimental_option('excludeSwitches', ['enable-logging'])\r\n    options.add_experimental_option(\"detach\", True)\r\n    driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options=options)\r\n    driver.maximize_window()\r\n    self.driver = driver\r\n  def read_file(self,path):\r\n    f = open(path, \"rt\")\r\n    text= f.read()\r\n    return text\r\n\r\n  def open_url(self,url):\r\n    self.driver.get(url)\r\np1 = Init()\r\nall_links_with_data = p1.open_url(\"https:\/\/google.com\")<\/code><\/pre>","category_id":"19","is_private":"0","created_at":"2023-04-02T11:13:01.000000Z","updated_at":"2025-01-26T02:52:24.000000Z","category":{"id":19,"user_id":"1","name":"Python Selenium","slug":"python-selenium-vbxw","parent_id":"5","created_at":"2023-04-02T11:11:46.000000Z","updated_at":"2023-04-02T11:11:46.000000Z"},"user":{"id":1,"name":"R GONDAL","email":"rizikmw@gmail.com","email_verified_at":null,"two_factor_confirmed_at":null,"current_team_id":"1","profile_photo_path":null,"created_at":"2023-03-12T10:49:33.000000Z","updated_at":"2025-01-10T12:59:00.000000Z","profile_photo_url":"https:\/\/ui-avatars.com\/api\/?name=R+G&color=7F9CF5&background=EBF4FF"}},"pageDesc":"DOCUMENTATION https:\/\/selenium-python.readthedocs.io\/ &nbsp; 1. Install python3 https:\/\/www.python.org\/downloads\/ 2. Run command in cmd pip  - Installation & runing Selenium basic example (Updated: January 26, 2025) - Read more about Installation & runing Selenium basic example at my programming site [SITE]","categories":[]}