1

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)
jest3rz
  • 21
  • 5
  • is browser launched when you ran this code? – Dev Sep 26 '19 at 13:54
  • Yeah, the browser is launched and the website opens fine. However, it seems to be continually loading/frozen after that. – jest3rz Sep 26 '19 at 13:55
  • @jest3rz What is your next step? – undetected Selenium Sep 26 '19 at 15:36
  • @debanjanb to send.keys to the login form to login to the website. I can't access the login form though because the webpage is unresponsive and sits loading. – jest3rz Sep 26 '19 at 15:53
  • @jest3rz - I also reproduced page is unresponsive when automation script opens it. works fine on manual. I am also waiting to see the answer. – Amit Jain Sep 26 '19 at 17:50
  • @AmitJain whats odd is the regular costco.com website works, albeit slowly. – jest3rz Sep 26 '19 at 18:14
  • @jest3rz => manually it works fast, page load time is fast. – Amit Jain Sep 26 '19 at 18:16
  • @AmitJain Yeah, I meant with Selenium. Costco.com works but costcobusinessdelivery.com doesn't. Very odd – jest3rz Sep 26 '19 at 18:19
  • It's possible that costcobusinessdelivery.com restricts access for automation browsers. From what I understand, these sites can detect where traffic originates from, and they might block any traffic that is not sourced from manual clicks. – CEH Sep 26 '19 at 20:55

1 Answers1

0

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

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • the new code doesn't work, selenium sits on the www.costcobusinessdelivery.com webpage and never loads. After about 5 minutes I get this error: TimeoutException: Message: timeout (Session info: chrome=77.0.3865.75) – jest3rz Sep 27 '19 at 13:17