1

Everyone. I hope you are going well. I have one problem to scrape the data from a specific URL.

driver = webdriver.Chrome()
driver.set_window_size(1200, 800)
driver.get(DEGIRO_URL)
loginUsername = driver.find_element_by_xpath("//input[@id='username']")
loginPassword = driver.find_element_by_xpath("//input[@id='password']")
loginBtn = driver.find_element_by_xpath("//button[@type='submit']")
loginUsername.send_keys(LOGIN_USERNAME)
loginPassword.send_keys(LOGIN_PASSWORD)
loginBtn.click()
try:
   myElem = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, 
            "//button[@class='duvfw-AB']")))
   myElem.click()
   print ("Page is ready!")
except TimeoutException:
    print ("Loading took too much time!")

When I run this code this shows me the following issues.

DevTools listening on ws://127.0.0.1:51297/devtools/browser/bf64f196-95fe-4df6-8ac8-2761849a317b
[19408:18516:0615/034317.403:ERROR:device_event_log_impl.cc(214)] [03:43:17.403] Bluetooth: bluetooth_adapter_winrt.cc:1072 Getting Default Adapter failed.
Traceback (most recent call last):
  File "E:\Work\scraping\scrape.py", line 83, in main
    myElem = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//button[@class='duvfw-AB']")))
  File "C:\Users\SingSong\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "E:\Work\scraping\scrape.py", line 147, in <module>
    main()
  File "E:\Work\scraping\scrape.py", line 86, in main
    except TimeoutException:
NameError: name 'TimeoutException' is not defined

If you have experience in this field, Please help me. Best Regards.

4
  • Have you imported it from the selenium module? Commented Jun 15, 2021 at 1:34
  • Yes, I have imported all library. from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By import pandas as pd import requests import lxml.html import time import json Commented Jun 15, 2021 at 1:35
  • then you have missed importing the exception, please see my answer to fix the issue Commented Jun 15, 2021 at 1:36
  • Where can I see your answers? Commented Jun 15, 2021 at 1:40

1 Answer 1

2

I am guessing that you have not imported the exception from the selenium module,

simply import it by

from selenium.common.exceptions import TimeoutException

Sign up to request clarification or add additional context in comments.

3 Comments

I have see this answer and insert this to my code.
This is working but I can't click the button.
Loading took too much time! I see this message.

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.