0

I'm trying to use selenium to log into Ingram Micro's website. My script works on other sites but when I try to use it on Ingram Micro I get this error/message:

selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <input class="button button-primary" type="submit" value="Log in" id="okta-signin-submit" data-type="save"> is not clickable at point (365, 560). Other element would receive the click: <p class="cc_message">...</p>

Here is my script:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.common.exceptions import NoSuchElementException 
from selenium.webdriver.common.keys import Keys
from bs4 import BeautifulSoup
import time

chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')

url = "https://usa.ingrammicro.com/_layouts/CommerceServer/IM/Login.aspx?returnurl=//usa.ingrammicro.com/"
driver = webdriver.Chrome(options=chrome_options)
driver.get(url)

def login():
    USERNAME = 'email'
    PASSWORD = 'password'
    driver.find_element_by_xpath("//input[@type='text']").send_keys(USERNAME)
    driver.find_element_by_xpath("//input[@type='password']").send_keys(PASSWORD)
    #driver.find_element_by_xpath("//input[@type='submit']").click()
    html = driver.find_element_by_tag_name('html')
    html.send_keys(Keys.END)
    driver.find_element_by_link_text('I ACCEPT').click()             
    driver.find_element_by_id('okta-signin-submit').click()
    

def write():
    with open('scraped.txt', 'w') as file:
        file.write(str(soup))

login()
html = driver.page_source
soup = BeautifulSoup(html, 'html.parser')
 
try:   
    me = driver.find_element_by_id("login_help-about") 
    #links = soup.find_all("a")
    #print(f"Found these links: {links}")
    #write()
    print(f"{me.text} Element found")
    
except NoSuchElementException:
    print('Not found')

driver.quit()

Update

I added some suggestions.

halfer
  • 19,824
  • 17
  • 99
  • 186
robothead
  • 303
  • 2
  • 10

3 Answers3

1

There is a message at the very bottom of the page which asks you to accept the cookies. When you're trying to click "Log in" you actually click on that message

You can accept the cookies before clicking "Log in":

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
...
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CLASS_NAME, "cc_btn_accept_all"))).click()
driver.find_element_by_id('okta-signin-submit').click()

You can also scroll the page to "unhide" "Log in" button:

from selenium.webdriver.common.keys import Keys

html = driver.find_element_by_tag_name('html')
html.send_keys(Keys.END)
JaSON
  • 4,843
  • 2
  • 8
  • 15
  • thanks for the reply, I tried what first wrote and now I get a message saying that element doesnt exist I also added the scroll that you mentioned but am not sure if Im using it right, either case Im still not getting logged in, I edited my code to show the changes you suggested – robothead Aug 12 '20 at 15:32
  • @robothead scroll should be performed before clicking LogIn – JaSON Aug 12 '20 at 15:57
  • I have moved the scroll code to several different spots, its not working, – robothead Aug 12 '20 at 16:02
  • @robothead and the exception is always the same? – JaSON Aug 12 '20 at 16:05
  • well since i added the accept cookie code I get this message:selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"link text","selector":"I ACCEPT"} – robothead Aug 12 '20 at 16:26
0

The error is actually quite helpful on this, you're asking it to click on a non clickable element. You can try fixing it by using co-ordinates instead of the name, add waits to make sure the page is loaded and maximizing the browser window.

I'm sure there are plenty of other ways of resolving this aswell.

Spaceglider
  • 97
  • 11
0

Try to scroll to elements before clicking on them. First click on the cookie accept button then click on the login button.

element = driver.find_element_by_css("cc_message")

actions = ActionChains(driver)
actions.move_to_element(element).perform()

if this does not work use a js scroll:

driver.execute_script("arguments[0].scrollIntoView();", element)

In case selenium click does not work try a js click.

driver.execute_script("arguments[0].click();", element)

Then scroll back to the login button if necessary before clicking it.

In case you're curious to know what's the difference between the js scroll and selenium move to element, check this.

Owkay
  • 11
  • 3