1

I am aiming to use my raspberry pi to test a webpage with python/selenium. The code works well on my desktop but the raspberry fail to handle the pop up:

driver = webdriver.Chrome()
driver.get("https://www.swoodoo.ch")
wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//div[@aria-label='Schliessen']"))).click()

No problem on the desktop (ubuntu 22.04 or linux mint) On the raspberry (raspberian or ubuntu 22.04) I get a timeout exception:

Traceback (most recent call last):
  File "/home/user/flights/flights2.py", line 19, in <module>
    wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//div[@aria-label='Schliessen']"))).click()
  File "/home/user/.local/lib/python3.9/site-packages/selenium/webdriver/support/wait.py", line 95, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 

I tried the following (all below works well on the desktop!):

a) I manually click the banner away -> the whole program fine, incl. the functions to grad text out of a search result. However, it is not automated

b) I added waiting time (

time.sleep(x))

between all lines, long waiting time (30+) -> no change

c) I changed the code to the following:

driver = webdriver.Chrome()

driver.get("https://www.swoodoo.ch")

time.sleep(5)

element=driver.find_element(By.XPATH, "//div[@aria-label='Schliessen']")

time.sleep(5)

element.click()

-> The computer finds the Element but it is not clickable, error code:

Traceback (most recent call last):
  File "/home/user/flights/flights2.py", line 23, in <module>
    element.click()
  File "/home/user/.local/lib/python3.9/site-packages/selenium/webdriver/remote/webelement.py", line 93, in click
    self._execute(Command.CLICK_ELEMENT)
  File "/home/user/.local/lib/python3.9/site-packages/selenium/webdriver/remote/webelement.py", line 401, in _execute
    return self._parent.execute(command, params)
  File "/home/user/.local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 440, in execute
    self.error_handler.check_response(response)
  File "/home/user/.local/lib/python3.9/site-packages/selenium/webdriver/remote/errorhandler.py", line 245, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
  (Session info: chrome=104.0.5112.105)
Stacktrace:
#0 0x00557fda2268 <unknown>
#1 0x00557fbcbb08 <unknown>
#2 0x00557fbfd50c <unknown>
#3 0x00557fbf32d0 <unknown>
#4 0x00557fbf2cac <unknown>
#5 0x00557fc264c8 <unknown>
#6 0x00557fbf18f0 <unknown>
#7 0x00557fde52f4 <unknown>
#8 0x00557fde7b9c <unknown>
#9 0x00557fdd1cd4 <unknown>
#10 0x00557fde83bc <unknown>
#11 0x00557fdc6d64 <unknown>
#12 0x00557fe01cd0 <unknown>
#13 0x00557fe01e40 <unknown>
#14 0x00557fe1a6f0 <unknown>

d) Last idea was to use javascript for the click

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

-> No error message, no action

Anyone any ideas?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
vhuber
  • 11
  • 3
  • 1
    Is the webpage visibly rendering the same? Media queries could be causing the content to switch to a mobile view or something similar – Libra Jan 10 '23 at 21:35
  • Yes,looks exactly the same on all devices.... Using even same Chromium version... – vhuber Jan 10 '23 at 21:38

1 Answers1

0

Generally <div> tags aren't clickable. So to click on the X icon you need to target the descendant <span> inducing WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    driver.get('https://www.swoodoo.ch/')
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div[aria-label='Schliessen'] > span"))).click()
    
  • Using XPATH:

    driver.get('https://www.swoodoo.ch/')
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@aria-label='Schliessen']/span"))).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
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thank you for the tow suggestions, unfortunately both end up with the same timeout error Traceback (most recent call last): File "/home/user/flights/flights2.py", line 19, in wait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, "//div[@aria-label='Schliessen']/span"))).click() File "/home/user/.local/lib/python3.9/site-packages/selenium/webdriver/support/wait.py", line 95, in until raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message: This drives me crazy........ – vhuber Jan 11 '23 at 20:15
  • @vhuber A bit clueless as the locators worked on my Win10 system seamlessly. – undetected Selenium Jan 11 '23 at 20:17
  • Me too, as it works on my linux desktop as well...... – vhuber Jan 12 '23 at 10:41