Reputation: 143
I have a problem with Selenium.
def main_test():
chrome_options = Options()
prefs = {"download.default_directory": f"{os.getcwd()}/Music"}
chrome_options.add_argument("user-data-dir=selenium")
chrome_options.add_experimental_option("prefs", prefs)
dr = webdriver.Chrome(options=chrome_options, service=Service(ChromeDriverManager().install()))
dr.get(URL)
print(f"{selenium.__version__=}")
dr.find_element(By.XPATH, "/html/body/div[1]/div[1]/div/div[1]/ul/li[2]/a").click()
dr.quit()
if __name__ == '__main__':
main_test()
This is my code. I think i followed properly the documentation. Although, when running the app i get this error:
selenium.__version__='4.6.0'
Traceback (most recent call last):
File "/Users/andrea/Dev/Python/custom_scripts/ytchannel/main.py", line 142, in <module>
main_test()
File "/Users/andrea/Dev/Python/custom_scripts/ytchannel/main.py", line 137, in main_test
dr.find_element(By.XPATH, "/html/body/div[1]/div[1]/div/div[1]/ul/li[2]/a").click()
AttributeError: type object 'By' has no attribute 'XPATH'
I have no clue on what i'm doing wrong... I can add every detail possible if needed.
Here my imports:
import socket
import httpcore
import re
import os
import json
import selenium
import httpx as web
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
from bs4 import BeautifulSoup
from time import sleep
Upvotes: 1
Views: 4004