jest3rz
jest3rz

Reputation: 21

How do I get my clicks to work on the website https://www.costcobusinessdelivery.com using Selenium through Python

When I run this code in Selenium is simply sits there loading the web page forever. Is anyone able to get this code to work and bring me to the login form?

from selenium import webdriver;
from selenium.webdriver.support.ui import Select;
from selenium.webdriver.common.keys import Keys;
from selenium.webdriver.common.by import By;
from selenium.webdriver.chrome.options import Options;
from selenium.webdriver.support.ui import WebDriverWait;
from selenium.webdriver.support import expected_conditions as EC;
import time;



browser = webdriver.Chrome()
browser.get('https://www.costcobusinessdelivery.com')

WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a#header_sign_in"))).click()

After about 5 minutes of the webpage remaining unresponsive I get this error:

TimeoutException                          Traceback (most recent call last)
<ipython-input-6-47279e187da7> in <module>
     11 
     12 browser = webdriver.Chrome()
---> 13 browser.get('https://www.costcobusinessdelivery.com')
     14 
     15 WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a#header_sign_in"))).click()

C:\ProgramData\Anaconda\lib\site-packages\selenium\webdriver\remote\webdriver.py in get(self, url)
    331         Loads a web page in the current browser session.
    332         """
--> 333         self.execute(Command.GET, {'url': url})
    334 
    335     @property

C:\ProgramData\Anaconda\lib\site-packages\selenium\webdriver\remote\webdriver.py in execute(self, driver_command, params)
    319         response = self.command_executor.execute(driver_command, params)
    320         if response:
--> 321             self.error_handler.check_response(response)
    322             response['value'] = self._unwrap_value(
    323                 response.get('value', None))

C:\ProgramData\Anaconda\lib\site-packages\selenium\webdriver\remote\errorhandler.py in check_response(self, response)
    240                 alert_text = value['alert'].get('text')
    241             raise exception_class(message, screen, stacktrace, alert_text)
--> 242         raise exception_class(message, screen, stacktrace)
    243 
    244     def _value_or_default(self, obj, key, default):

TimeoutException: Message: timeout
  (Session info: chrome=77.0.3865.75)

Upvotes: 1

Views: 127

Answers (1)

undetected Selenium
undetected Selenium

Reputation: 193108

To click() on the link with text as Sign In / Register within the website https://www.costcobusinessdelivery.com/ you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using PARTIAL_LINK_TEXT:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, "Sign In / Register"))).click()
    
  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a#header_sign_in"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@id='header_sign_in']"))).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
    
  • Browser Snapshot:

costco_login

Upvotes: 0

Related Questions