1

I am trying to login to a website using python so that I can get some of their text from the website.

Here is my code. There always an error at the end of the code after the id and password code.

import os
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC 
from selenium.webdriver.common.by import By

driver = webdriver.Chrome(executable_path=r"C:\chromedriver\chromedriver.exe")

driver.get('https://www.saramin.co.kr/zf_user/auth')

driver.implicitly_wait(3)

driver.find_element_by_name('id').send_keys('<<my_id>>')
driver.find_element_by_name('password').send_keys('<<my_password>>')

driver.find_element_by_xpath('//*[@id="frmNIDLogin"]/fieldset/input').click()

HTML source of the button:

enter image description here

1
  • 1
    The html doesn't match the xpath in your code. And post the html as text please, not as an image. Commented Dec 4, 2018 at 7:08

3 Answers 3

1

Eventually I figured it out! Thanks for your answer though.

Here is the final code.

driver = webdriver.Chrome(executable_path="C:\chromedriver\chromedriver.exe")

browser = webdriver.Chrome('C:\chromedriver\chromedriver.exe')

driver.get('https://www.saramin.co.kr/zf_user/auth')

driver.implicitly_wait(3)

driver.find_element_by_name('id').send_keys('ID') driver.find_element_by_name('password').send_keys('PW')

driver.find_element_by_xpath( '//*[@class="btn-login"]' ).click()
Sign up to request clarification or add additional context in comments.

1 Comment

It worth noticing '//*[@class="btn-login"]' match two elements. It works because the relevant element is first in the DOM hierarchy, it might not always be that way.
0

The xpath is incorrect, it doesn't match anything in the page. Try

driver.find_element_by_xpath('//form[@id="login_frm"]//button[@class="btn-login"]').click()

or simply use submit() function on the <form>

form = driver.find_element_by_id('login_frm')
form.submit()

Comments

0

In the first case you were using 'id' ('//*[@id="frmNIDLogin"]) for click button, because 'id' changes every time page loads it was giving error. But in the second case when you used class ( '//*[@class="btn-login"]' ) it worked because it remains same every time page is loaded. Also as mentioned above the value of id in first case was wrong.

Comments

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.