Takes 1 positional argument but 2 were given

Hi everyone,

in this programm the error that always occurs is “TypeError: presence_of_element_located() takes 1 positional argument but 2 were given” for line 17, in element = WebDriverWait(driver, 10).until(EC.presence_of_element_located(By.ID,“menu-item-511”))… Now, does the programm take the “By.ID” and “menu-item-511” as two different positional arguments?? Probably the worst question, but I got stuck there for a day. It would be great if someone would take time and reply :wink: thanks !

from selenium import webdriver from selenium.webdriver.common.keys import Keys import time 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 path="C:\chromedriver.exe" driver = webdriver.Chrome(path) driver.get("https://www.techwithtim.net/") link=driver.find_element_by_link_text("Python Programming") link.click() try: element = WebDriverWait(driver, 10).until(EC.presence_of_element_located(By.ID,"menu-item-511")) element.click() finally: driver.quit()

the Codebyte won’t work b/c it cannot import modules or files from your local drive.

What is the link to the lesson or project to which you are referring?

If you define a method inside of a class you have to add/pass selfas the first argument or else you’ll get this type error.

Also:
https://stackoverflow.com/questions/23944657/typeerror-method-takes-1-positional-argument-but-2-were-given

1 Like

If you’re passing two arguments separated by a , to a function/method call then yes they’re separate items.

Perhaps you meant to pass a tuple? You can use , on its own to create tuples only when it’s unambiguous otherwise you’d need a second set of brackets to create the tuple object first.

def func(*obj): for elem in obj: print(obj, type(obj)) print("pass two distinct objects") func(1, 2) print("pass a single tuple") func((1, 2))
1 Like

Thanks for your reply. I solved it by just using find_element_by_class_name(“entry-header”) without using a plural “s” in elements, thereby skipping the by.ID-problem.