-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSelenium_automate
43 lines (34 loc) · 1.31 KB
/
Selenium_automate
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Install necessary packages
!apt-get update
!apt-get install -y wget unzip
!wget https://chromedriver.storage.googleapis.com/114.0.5735.90/chromedriver_linux64.zip
!unzip chromedriver_linux64.zip
!cp chromedriver /usr/local/bin/chromedriver
!apt-get install -y chromium-browser
# Install Python packages
!pip install selenium pyvirtualdisplay
# Import necessary libraries
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from pyvirtualdisplay import Display
# Set up virtual display
display = Display(visible=0, size=(1024, 768))
display.start()
# Set up Chrome options
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--remote-debugging-port=9222') # Optional, useful for debugging
# Specify the path to the Chromium binary
chrome_options.binary_location = '/usr/bin/chromium-browser'
# Set up the webdriver
service = Service('/usr/local/bin/chromedriver')
driver = webdriver.Chrome(service=service, options=chrome_options)
# Example: Open a webpage and print the title
driver.get('https://www.example.com')
print(driver.title)
# Close the driver and virtual display
driver.quit()
display.stop()