You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
( I use win64 and these are official google links. If you don't trust just google how to download drivers and replace 127.0.6533.120 with whatever version you want )
Code =
import time
import undetected_chromedriver as uc
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import WebDriverException
Path to your ChromeDriver executable
chromedriver_path = r"path to dirver"
Path to the Chrome executable for version 127
chrome_executable_path = r"Path to your chrome"
Create Chrome options
options = uc.ChromeOptions()
options.binary_location = chrome_executable_path # Specify the path to Chrome
options.add_argument('--no-sandbox') # Bypass OS security model
options.add_argument('--disable-dev-shm-usage') # Overcome limited resource problems
options.add_argument('--disable-extensions') # Disable extensions
options.add_argument('--headless') # Uncomment to run in headless mode (optional)
Launch the Chrome browser with the specified ChromeDriver path
# Navigate to a website
print("Navigating to YouTube...")
driver.get('https://www.youtube.com')
# Optional sleep to allow page to load
time.sleep(5)
# Wait for the specific element to be present using XPath
print("Waiting for the logo element to be present...")
element = WebDriverWait(driver, 20).until(
EC.presence_of_element_located((By.XPATH, '//*[@id="logo-icon"]/span/div')) # Using the provided XPath
)
# Perform any actions you need here
print("Element found. Page title:", driver.title) # Print the title of the page
time.sleep(100) # Adjust the sleep time as needed
except WebDriverException as e:
print(f"WebDriver error: {e}")
except Exception as e:
print(f"An error occurred: {e}")
finally:
# Ensure the driver is quit properly
try:
print("Closing the driver...")
driver.quit()
except Exception as e:
print(f"An error occurred while closing the driver: {e}")
The text was updated successfully, but these errors were encountered:
cuppjj
changed the title
Fix for people who are just starting
dont click
Oct 8, 2024
cuppjj
changed the title
dont click
Fix for people who are just starting
Oct 8, 2024
Chrome driver download = https://storage.googleapis.com/chrome-for-testing-public/127.0.6533.120/win64/chromedriver-win64.zip
Chrome download = https://storage.googleapis.com/chrome-for-testing-public/127.0.6533.120/win64/chrome-win64.zip
( I use win64 and these are official google links. If you don't trust just google how to download drivers and replace 127.0.6533.120 with whatever version you want )
Code =
import time
import undetected_chromedriver as uc
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import WebDriverException
Path to your ChromeDriver executable
chromedriver_path = r"path to dirver"
Path to the Chrome executable for version 127
chrome_executable_path = r"Path to your chrome"
Create Chrome options
options = uc.ChromeOptions()
options.binary_location = chrome_executable_path # Specify the path to Chrome
options.add_argument('--no-sandbox') # Bypass OS security model
options.add_argument('--disable-dev-shm-usage') # Overcome limited resource problems
options.add_argument('--disable-extensions') # Disable extensions
options.add_argument('--headless') # Uncomment to run in headless mode (optional)
Launch the Chrome browser with the specified ChromeDriver path
try:
print("Launching Chrome...")
driver = uc.Chrome(executable_path=chromedriver_path, options=options)
except WebDriverException as e:
print(f"WebDriver error: {e}")
except Exception as e:
print(f"An error occurred: {e}")
finally:
# Ensure the driver is quit properly
try:
print("Closing the driver...")
driver.quit()
except Exception as e:
print(f"An error occurred while closing the driver: {e}")
The text was updated successfully, but these errors were encountered: