0

I am trying to scrape some information from the below website. I am new to this so dont fully understand what is happening. I have basically been sourcing information from various examples i have found on internet I am using selenium and python to help me navigate to the page from where i can scrape some information I have used the below script I am able to navigate to the home page , close cookies and click on sign in . at this point a pop up opens up for entering user id and password the div element is not being identified , each time i get error saying no such element is present i added the wait with expected conditions , however i get the below error

C:\Users\user\AppData\Local\Programs\Python\Python38-32\SeleniumWebscraper2.py:14: DeprecationWarning: use options instead of chrome_options browser = webdriver.Chrome(executable_path="C:/Users/user/Downloads/chromedriver_win32/chromedriver.exe", chrome_options=chrome_options)

DevTools listening on ws://127.0.0.1:2672/devtools/browser/f6aca700-5569-4367-9ceb-71e88fcc3082 CDwindow-BD7440D2580236DB9EEFE8B8FE1730D6 0 Traceback (most recent call last): File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\SeleniumWebscraper2.py", line 37, in browser.find_element_by_xpath("//button[@class='gigya-input-text']").send_keys('[email protected]') File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 394, in find_element_by_xpath return self.find_element(by=By.XPATH, value=xpath) File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 976, in find_element return self.execute(Command.FIND_ELEMENT, { File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute self.error_handler.check_response(response) File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//button[@class='gigya-input-text']"} (Session info: chrome=78.0.3904.97) https://education.independent.ie/league

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 
from selenium.common.exceptions import TimeoutException
import requests
from bs4 import BeautifulSoup


chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("prefs", {"profile.default_content_settings.cookies": 2})


browser = webdriver.Chrome(executable_path="C:/Users/user/Downloads/chromedriver_win32/chromedriver.exe", chrome_options=chrome_options)

browser.get("https://education.independent.ie/league/school/abbey-community-college-roscommon-558")

browser.implicitly_wait(10) # seconds

selector = ".gigya-input-text"


main_window_handle = None
while not main_window_handle:
    main_window_handle = browser.current_window_handle
    print(main_window_handle)
browser.find_element_by_xpath("//button[@class='qc-cmp-button']").click()


WebDriverWait(browser, 10)
browser.switch_to.window(browser.current_window_handle)
browser.find_element_by_xpath("//button[@class='button-b gigya-sign-in']").send_keys('\n')


WebDriverWait(browser, 120).until(EC.visibility_of_element_located((By.CSS_SELECTOR, selector )))
print(len(browser.find_elements_by_id("gigya-input-text")))
browser.find_element_by_xpath("//button[@class='gigya-input-text']").send_keys('[email protected]')

2 Answers 2

2

try this:

# import web driver
from selenium import webdriver

# specifies the path to the chromedriver.exe
driver = webdriver.Chrome("/opt/anaconda2/chromedriver")

# driver.get method() will navigate to a page given by the URL address
driver.get("https://www.linkedin.com/login?") 


# locate email form by_name
username = driver.find_element_by_name('session_key')

# locate email form by_xpath
#username = driver.find_element_by_xpath('//*[@id="username"]')

# locate email form by_id
#username = driver.find_element_by_id("username")

#send_keys() to simulate key strokes
username.send_keys("[email protected]")

# locate password form by_name
#password = driver.find_element_by_name('session_password')

#locate password form id
#password = driver.find_element_by_id("password")

#locate password form by_xpath
password = driver.find_element_by_xpath('//*[@id="password"]')


# send_keys() to simulate key strokes
password.send_keys("password")

# locate submit button by_class_name
log_in_button = driver.find_element_by_class_name('btn__primary--large')

# locate submit button by_xpath
#log_in_button = driver.find_element_by_xpath('//*[@type="submit"]')

# .click() to mimic button click
log_in_button.click()
Sign up to request clarification or add additional context in comments.

2 Comments

i think this won't work, as i am not able to locate the element which has login credentials
0

You are getting this error because the part of id gig_1574604202288_showScreenSet that your are trying to find is random. You can use other selector to locate this element e.g. (By.CSS_SELECTOR, "div[id*='showScreenSet']"). You can read about this more here and practice here.

Also WebDriverWait(browser, 120) does nothing. If you want global wait you can use implicit wait. Read about this here.

1 Comment

i added a CSS selector, I still get the error that the element cant be found. Would it be possible to see if you are able to decode and login in to this website

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.