Just started experimenting with selenium 4 using Python, I want to work with HtmlUnit too (to be deployed in a Debian OS without GUI).
So I installed selenium-server-standalone-3.5.3.jar
and I run it on http://127.0.0.1:4444/wd/hub
.
But I got this error:
$ python selenium/myfile.py
Traceback (most recent call last):
File "APPLICATION_PATH\selenium\myfile.py", line 81, in <module>
Choices= TabList.find_elements(By.XPATH, '//li[@role="presentation"]')
AttributeError: 'dict' object has no attribute 'find_elements'
This is a piece of code with line 79 :
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from os.path import join, basename, dirname
import time
import datetime
import custom_wait_conditions as CWC
import os
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options as ChromeOptions
from selenium.webdriver.chrome.service import Service as ChromeService
def mkdir_p(path):
try:
isExist = os.path.exists(path)
if not isExist:
os.makedirs(path, exist_ok=True)
except (os.error, e):
print(e.errno)
ROOT_DIR = os.path.abspath(os.curdir)
today = datetime.date.today();
today_date = str(today.strftime("%d/%m/%Y"))
download_folder = ROOT_DIR + r"\download"
# Create download files Folter if notexist
mkdir_p(download_folder);
chrome_options = webdriver.ChromeOptions()
chrome_options.set_capability("browserName", "htmlunit")
chrome_options.set_capability("version", "9.4.5.v20170502")
chrome_options.set_capability("platform", "WIN10")
chrome_options.set_capability("cssSelectorsEnabled", True)
chrome_options.set_capability("javascriptEnabled", True)
chrome_options.set_capability("w3c", True)
driver = webdriver.Remote(
command_executor='http://127.0.0.1:4444/wd/hub',
options=chrome_options
)
driver.get("THE_TARGET_LINK")
startDate = driver.find_element(By.ID, 'txtDateD')
endDate = driver.find_element(By.ID, 'txtDateF')
searchButton = driver.find_element(By.ID, 'btnRechercheAnnByDateTypeJur')
TabList = driver.find_element(By.XPATH, '//ul[@role="tablist" and
@class="nav nav-pills TypeJuridiction"]')
Choices = TabList.find_elements(By.XPATH, '//li[@role="presentation"]')
resultTab = driver.find_element(By.ID, 'Res')
resultDetails = driver.find_element(By.ID, 'Res_Detail')
startDate.send_keys("14/03/2022")
endDate.send_keys(today_date)
I tried to disable some capabilities options, but I got the same error.