Home > Software design >  Uploading a file to the //span element selenium
Uploading a file to the //span element selenium

Time:09-08

I have an element that offers to upload a file by clicking: <a href="#">Upload archive<span>Supported types: .zip, .mcworld</span></a>

I tried to do it like this:

elm = driver.find_element('//span[text="Upload archive"]')

returns an error:

Traceback (most recent call last):
  File "/home/lyaguxa/Projects/chunks/main.py", line 53, in <module>
    elm = driver.find_element('//span[text="Upload archive"]')
  File "/home/lyaguxa/.local/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 855, in find_element
    return self.execute(Command.FIND_ELEMENT, {
  File "/home/lyaguxa/.local/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 428, in execute
    self.error_handler.check_response(response)
  File "/home/lyaguxa/.local/lib/python3.10/site-packages/selenium/webdriver/remote/errorhandler.py", line 243, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: invalid locator
  (Session info: chrome=105.0.5195.102)

then I tried to do this:

wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Upload archive']"))).click()
Traceback (most recent call last):
  File "/home/lyaguxa/Projects/chunks/main.py", line 51, in <module>
    wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Upload archive']"))).click()
  File "/home/lyaguxa/.local/lib/python3.10/site-packages/selenium/webdriver/support/wait.py", line 90, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 

How do I do this? I don't understand anything anymore

CodePudding user response:

What is your test web address? Give this a try:

wait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "[href='#']"))).click()
  • Related