Home > Enterprise >  How can I log in with selenium in a page?
How can I log in with selenium in a page?

Time:11-18

I try to log into my school account with my credentials to fill out 10 long surveys that each semester they make us fill out, otherwise we can't perform any functions. I am using selemiun webdriver to automate everything while I sleep.

I try to log in with the following code:

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

USERNAME = xxxxxxx
PASSWORD = xxxxxxx

driver = webdriver.Chrome('C:\Dev\WebDrivers\garou-bruteforce-master\chromedriver.exe')
driver.get('http://siiauescolar.siiau.udg.mx/')
wait = WebDriverWait(driver, 10)
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'input[name="p_codigo_c"]'))).send_keys(USERNAME)
driver.find_element_by_css_selector('input[name="p_clave_c"]').send_keys(PASSWORD)
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'input[type="submit"]'))).click()

But get this error:

selenium.common.exceptions.TimeoutException: Message:
Stacktrace:
Backtrace:
        Ordinal0 [0x005F6023 2514979]
        Ordinal0 [0x0058F6B1 2094769]
        Ordinal0 [0x004926C8 1058504]
        Ordinal0 [0x004BD2D8 1233624]
        Ordinal0 [0x004BD4CB 1234123]
        Ordinal0 [0x004E7652 1406546]
        Ordinal0 [0x004D635A 1336154]
        Ordinal0 [0x004E59FF 1399295]
        Ordinal0 [0x004D61EB 1335787]
        Ordinal0 [0x004B2617 1189399]
        Ordinal0 [0x004B3479 1193081]
        GetHandleVerifier [0x00785624 1579748]
        GetHandleVerifier [0x00830417 2279639]
        GetHandleVerifier [0x0068473B 527355]
        GetHandleVerifier [0x006837E9 523433]
        Ordinal0 [0x00594BF9 2116601]
        Ordinal0 [0x00599238 2134584]
        Ordinal0 [0x00599372 2134898]
        Ordinal0 [0x005A2EB1 2174641]
        BaseThreadInitThunk [0x76D36359 25]
        RtlGetAppContainerNamedObjectPath [0x774F8944 228]
        RtlGetAppContainerNamedObjectPath [0x774F8914 180]

How can fix tihis? Thanks very much.

CodePudding user response:

Elements you are trying to access are inside a frame. You have to switch to that frame in order to access these elements.
Try this:

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

USERNAME = xxxxxxx
PASSWORD = xxxxxxx

driver = webdriver.Chrome('C:\Dev\WebDrivers\garou-bruteforce-master\chromedriver.exe')
driver.get('http://siiauescolar.siiau.udg.mx/')
wait = WebDriverWait(driver, 10)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"frame[name='mainFrame']")))
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'input[name="p_codigo_c"]'))).send_keys(USERNAME)
driver.find_element_by_css_selector('input[name="p_clave_c"]').send_keys(PASSWORD)
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'input[type="submit"]'))).click()
  • Related