0

I'm trying to login with seleinum automatically. I've used

  1. driver.execute_script
  2. driver.find_element_by_css_selector
  3. driver.find_element_by_xpath

.

from selenium import webdriver
from webdriver_manager import chrome

driver = webdriver.Chrome(chrome.ChromeDriverManager().install())
driver.get("https://naco999.com/")

driver.find_element_by_css_selector('#login_id').send_keys("id")
driver.find_element_by_css_selector("#login_pw").send_keys("pw")

But none of these seems to work. How can I?

1

1 Answer 1

2

There are 3 elements matching #login_id css_selector.
Try using this:

driver.find_element_by_css_selector(".header-one #login_id").send_keys("id")
driver.find_element_by_css_selector(".header-one #login_pw").send_keys("pw")

Also, you should add a wait to send the text when the elements are loaded.
Like this:

from selenium import webdriver
from webdriver_manager import chrome
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(chrome.ChromeDriverManager().install())
wait = WebDriverWait(driver, 20)

driver.get("https://naco999.com/")

wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".header-one #login_id"))).send_keys("id")
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".header-one #login_pw"))).send_keys("pw")

Sign up to request clarification or add additional context in comments.

12 Comments

Exactly! I was just going to write that!
So the selenium sended keys to another element?
Sure, it's simple :)
And that element is not actually visible here
Then, how can I know there's three same css_selector?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.