`
import requests
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from time import sleep
import os
login_page = "https://fap.fpt.edu.vn/Default.aspx"
# page = "https://fap.fpt.edu.vn/Report/ScheduleOfWeek.aspx"
email = ""
password = ""
options = Options()
options.add_argument("--window-size=1920,1080")
options.binary_location = "C:\Program Files\Google\Chrome\Application\chrome.exe"
driver = webdriver.Chrome(options = options)
driver.get(login_page)
login1 = driver.find_element("xpath","//div[@class='abcRioButtonContentWrapper']").click()
driver.find_element(By.NAME, "identifier").send_keys(email)
sleep(3)
driver.find_element(By.ID, "identifierNext").click()
sleep(2)
driver.find_element(By.NAME, "password").send_keys(password)
sleep(2)
driver.find_element(By.ID, "passwordNext").click()
sleep(999999)
`
I believe i chose the right By.NAME ( "indentifier" ) but the code still not work and return message no such element.
I tried to change the syntax, using xpath change By.NAME to By.ID but it still not work
CodePudding user response:
No, don't use name of jsname here, because they get filled with random data.
Just find your Google account name or your email address by text and click it:
userAccount = driver.find_element_by_xpath("//*[text()='YourGoogleAccountName']")
userAccount.click()
CodePudding user response:
Google login page opens in a new window. So you need to switch to this window before interacting with it. So you need to use this code (the first and the last lines are from your code and between is the part you need to add):
login1 = driver.find_element("xpath","//div[@class='abcRioButtonContentWrapper']").click()
windows = driver.window_handles
driver.switch_to.window(windows[1])
driver.find_element(By.NAME, "identifier").send_keys(email)
And after you've finished with the login you will need to switch back to the main window. To do that you can use this code:
driver.switch_to.window(windows[0])
And then wirk with the content of the page