1

im trying to learn "Selenium" but i have a mistake in my codes but i cant find it. I imported some variable other file like that " from githubuser import username,password ". im trying to auto github signer but i cant :( can u help me ?

`

from selenium import webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from githubuser import username, password

class Github:
    def __init__(self,username,password):
        self.browser = webdriver.Chrome()
        self.username = username    
        self.password = password
    def signin(self):
        self.browser.get("https://github.com/login/")
        time.sleep(2)
        self.browser.find_element(By.XPATH,'//*[@id="login_field"]').username.send_keys(self.username) 
        self.browser.find_element(By.XPATH,'//*[@id="password"]').password.send_keys(self.password)

        time.sleep(2)
        self.browser.find_element(By.XPATH,'//*[@id="login"]/div[4]/form/div/input[11]').click()

github = Github(username = username, password = password)
github.signin()

`

ofowardar
  • 15
  • 4
  • Add more information, and specify your objective better. – RifloSnake Mar 02 '23 at 18:01
  • Also maybe have a look at playwright, which is the more modern version of what selenium was created for way back when. It's not Python, but it's a _lot_ better than Selenium. – Mike 'Pomax' Kamermans Mar 02 '23 at 18:12
  • Try removing `.username` from `self.browser.find_element(By.XPATH,'//*[@id="login_field"]').username.send_keys(self.username)`. Try with `self.browser.find_element(By.XPATH,'//*[@id="login_field"]').send_keys(self.username)`, Similarly do for the next line – sourin_karmakar Mar 02 '23 at 18:45

1 Answers1

0

To send a character sequence to the Username and Password field you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    driver.get('https://github.com/login/')
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#login_field"))).send_keys(username)
    driver.find_element(By.CSS_SELECTOR, "input#password").send_keys(password)
    driver.find_element(By.CSS_SELECTOR, "input[name='commit']").click()
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352