visibility_of_all_elements_located() takes 1 positional argument but 2 were given error

59 views
Skip to first unread message

Michael Fu

unread,
Apr 19, 2025, 9:06:37 AMApr 19
to Selenium Users
Ubuntu 24.04
Chrome Version 137.0.7127.2 (Official Build) dev (64-bit)
Selenium Version: 4.31.0
Python 3.12.3

I'm new to selenium, trying to learn by doing, I have a partial code
a = (By.XPATH, "//*[@id='bookingCruiseDetails']/div[2]/div[2]/div[1]/h3")
cruise_title = wait.until(EC.visibility_of_all_elements_located(a))

when I run this code, it gave me a blank page, but if I run this code instead
cruise_title = wait.until(EC.visibility_of_all_elements_located(By.XPATH, "//*[@id='bookingCruiseDetails']/div[2]/div[2]/div[1]/h3"))
it gave me this error > `visibility_of_all_elements_located() takes 1 positional argument but 2 were given`
What am I doing wrong? The complete code is as follows:
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 import webdriver
import time

options = webdriver.ChromeOptions()
# options.add_argument("--headless") # Run headless if you wish
options.add_experimental_option('detach', True)
driver = webdriver.Chrome(options=options)

# for url in self.cruise_urls:
try:
driver.maximize_window()
driver.get(url) #load a cruise page
wait = WebDriverWait(driver, 10)

# Below try catch code is to handle the cookie consent pop-up. If you are not getting this pop-up, you can remove this code.
try:
wait.until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Accept']"))).click()
except Exception as e:
print("Accept button not found or not clickable:", e)

time.sleep(1)
a = (By.XPATH, "//*[@id='bookingCruiseDetails']/div[2]/div[2]/div[1]/h3")
cruise_title = wait.until(EC.visibility_of_all_elements_located(a))
#cruise_title = wait.until(EC.visibility_of_all_elements_located(By.XPATH, "//h2[@class='bcd-title__title']"))
print("cruise title > " + cruise_title.text)
except Exception as e:
print(e)
driver.close()

Corey Goldberg

unread,
Apr 19, 2025, 10:24:44 AMApr 19
to seleniu...@googlegroups.com

That method takes a locator tuple... but you are passing 2 separate arguments.


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/selenium-users/028caa48-b1e1-4816-89b5-c32377a84efan%40googlegroups.com.

Adrian

unread,
Apr 21, 2025, 5:49:24 PMApr 21
to Selenium Users
Hi, Try using:
cruise_title = wait.until(EC.visibility_of_all_elements_located((By.XPATH"//*[@id='bookingCruiseDetails']/div[2]/div[2]/div[1]/h3")))
I've added some extra brackets.

However your other option is way better:
cruise_title = wait.until(EC.visibility_of_all_elements_located((By.XPATH, "//h2[@class='bcd-title__title']")))
I've added the extra brackets here too.

Cheers,
Adrian.
Reply all
Reply to author
Forward
0 new messages