Armand Jordaan
Armand Jordaan

Reputation: 348

Python: find_element() takes from 1 to 3 positional arguments but 6 were given

I have the following code to download a web page in Python using Selenium and Firefox. A part of the page is rendered with Javascript, so I want to wait until a phrase is rendered.

This is the code I am using:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException

def firefoxget(url: str, file: str):
    browser = webdriver.Firefox()
    browser.get(url)
    
    WebDriverWait(browser,30).until(EC.text_to_be_present_in_element(By.XPATH,"//*[contains(text(),'In Stock')]"))

    f = open(file, "w")
    f.write(browser.page_source)
    f.close()

    browser.close()

The problem is I get "find_element() takes from 1 to 3 positional arguments but 6 were given" at the WebDriverWait line. I am new to python, and unfortunately, it does not make sense to me since I cannot understand where 6 arguments come from.

Upvotes: 0

Views: 5024

Answers (2)

cruisepandey
cruisepandey

Reputation: 29362

Instead of

WebDriverWait(browser,30).until(EC.text_to_be_present_in_element(By.XPATH,"//*[contains(text(),'In Stock')]"))

try this :

WebDriverWait(browser,30).until(EC.visibility_of_element_located((By.XPATH,"//*[contains(text(),'In Stock')]")))

basically you are missing an open and close parenthesis. see near By.XPATH

Upvotes: 3

Prophet
Prophet

Reputation: 33361

The syntax you used for EC.text_to_be_present_in_element(By.XPATH,"//*[contains(text(),'In Stock')]") is wrong.

The syntax is:

class selenium.webdriver.support.expected_conditions.text_to_be_present_in_element(locator, text)

An expectation for checking if the given text is present in the specified element. locator, text

But I see no text value you are expecting to see in that element.
Maybe you just want to wait until this element becomes visible?
If so you should use visibility_of_element_located expected condition.
In you case:

WebDriverWait(browser,30).until(EC.visibility_of_element_located(By.XPATH,"//*[contains(text(),'In Stock')]"))

Upvotes: 0

Related Questions