0

I am trying to use Selenium to download a file from https://id.opswat.com, in order to access it I need to login, but I can't, because when I try to retrieve the email input, it gives me an error ... This is my code:

from selenium import webdriver

driver = webdriver.Chrome()
driver.get('https://id.opswat.com/login')
driver.find_element_by_name('email').send_keys('email@email.es')
driver.find_element_by_class_name('form--button is-primary is-fullwidth button').click()
driver.find_element_by_name('password').send_keys('pass')
driver.find_element_by_class_name('form--button is-primary is-fullwidth button').click()

And this is the error:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[name="email"]"}

The login on that page is a bit special, because first you have to enter the email, check that it is well formed, click to continue, and you will see the password entry and the button to log in ...

Maybe something very basic is missing me, but I can't find it ... (I've tried waits, but neither ...)

jmp
  • 71
  • 9

2 Answers2

0

I can't see anything obviously wrong with it, have you checked if you can get the driver.find_element_by_class_name('emailInputBox')? Or any other element in the page?

Does it work when getting by XPath?

//*[@id="root"]/div/section/div/div/div[2]/form/div[2]/div/div/div/input

You could also try waiting for the element to be present like in this answer:https://stackoverflow.com/a/50324722/10832847

endo.anaconda
  • 2,449
  • 4
  • 29
  • 55
Bubber
  • 11
  • 1
  • 1
0

First, your line

driver.find_element_by_class_name('form--button is-primary is-fullwidth button').click()

will always fail because class_name function does not handle spaces in the class. I'd suggest changing that to

driver.find_element_by_css_selector('.form--button.is-primary.is-fullwidth.button').click()

Next, You need to wait for the page to load before you try to interact with each field. This works for me:

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

driver = webdriver.Chrome()
driver.get('https://id.opswat.com/login')
WebDriverWait(driver, 15).until(EC.element_to_be_clickable((By.NAME, 'email'))).send_keys('email@email.es')
driver.find_element_by_css_selector('.form--button.is-primary.is-fullwidth.button').click()
WebDriverWait(driver, 15).until(EC.element_to_be_clickable((By.NAME, 'password'))).send_keys('pass')
driver.find_element_by_css_selector('.form--button.is-primary.is-fullwidth.button').click()
C. Peck
  • 3,641
  • 3
  • 19
  • 36
  • Thank you! Works :) I had tried wait too, but I must have done something wrong. I didn't know either class_name didn't support spaces. Now I have the difficult part, downloading the file. I'll try! Thank you! – jmp Jun 04 '21 at 11:55