Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Selenium not finding elements on specific website

I am trying to use Selenium on https://www.ticketswap.be/ with the following code:

driver = webdriver.Chrome()
driver.get('https://www.ticketswap.be/')
login_button = driver.find_element(by=By.XPATH, value='//*[@id="__next"]/div[5]/div/nav/ul/li[4]/button')

Unfortunately I get the following error:

---------------------------------------------------------------------------
NoSuchElementException                    Traceback (most recent call last)
<ipython-input-47-3a159bb5ece9> in <module>()
      1 driver = webdriver.Chrome(options = chrome_options)
      2 driver.get('https://www.ticketswap.be/')
----> 3 login_button = driver.find_element(by=By.XPATH, value='//*[@id="__next"]/div[5]/div/nav/ul/li[4]/button')

2 frames
/usr/local/lib/python3.7/dist-packages/selenium/webdriver/remote/errorhandler.py in check_response(self, response)
    245                 alert_text = value['alert'].get('text')
    246             raise exception_class(message, screen, stacktrace, alert_text)  # type: ignore[call-arg]  # mypy is not smart enough here
--> 247         raise exception_class(message, screen, stacktrace)
    248 
    249     def _value_or_default(self, obj: Mapping[_KT, _VT], key: _KT, default: _VT) -> _VT:

NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="__next"]/div[5]/div/nav/ul/li[4]/button"}
  (Session info: headless chrome=100.0.4896.127)
Stacktrace:
#0 0x562ead5a71b3 <unknown>
#1 0x562ead2962c3 <unknown>
#2 0x562ead2cc7a0 <unknown>
#3 0x562ead2cc9c1 <unknown>
#4 0x562ead301127 <unknown>
#5 0x562ead2ea11d <unknown>
#6 0x562ead2fee6c <unknown>
#7 0x562ead2ea463 <unknown>
#8 0x562ead2c063c <unknown>
#9 0x562ead2c1b05 <unknown>
#10 0x562ead5cba90 <unknown>
#11 0x562ead5dd378 <unknown>
#12 0x562ead5dd09c <unknown>
#13 0x562ead5dd902 <unknown>
#14 0x562ead615f0b <unknown>
#15 0x562ead5ddb61 <unknown>
#16 0x562ead5bffd3 <unknown>
#17 0x562ead5e72b8 <unknown>
#18 0x562ead5e744a <unknown>
#19 0x562ead600291 <unknown>

I have tried to use other elements to find the login button but none work on this specific website. I also used the same code on other website to locate elements there and it worked. Can anyone help me out to make this work?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You need to do the following:

  1. Click on accept button.
  2. Click on close language button.

Code:

driver = webdriver.Chrome()
driver.maximize_window()
wait = WebDriverWait(driver, 20)

driver.get("https://www.ticketswap.be/")
wait = WebDriverWait(driver, 20)

try:
    wait.until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Accepteer']"))).click()
    print("Clicked on accept cookies button successfully")
    try:
        wait.until(EC.element_to_be_clickable((By.XPATH, "//*[name()='svg' and @aria-label='CloseRounded']"))).click()
        print("clicked on close language button")
    except:
        print("Could not click on close language button")
        pass
except:
    print("Could not click accept cookies button successfully")
    pass

wait.until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Inloggen']"))).click()

Imports:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

Output:

Clicked on accept cookies button successfully
clicked on close language button

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading