Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for people who are just starting #2042

Open
cuppjj opened this issue Oct 8, 2024 · 0 comments
Open

Fix for people who are just starting #2042

cuppjj opened this issue Oct 8, 2024 · 0 comments

Comments

@cuppjj
Copy link

cuppjj commented 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)

# 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}")

@cuppjj cuppjj changed the title Fix for people who are just starting dont click Oct 8, 2024
@cuppjj cuppjj changed the title dont click Fix for people who are just starting Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant