1
votes

I am trying to scrape the following website: https://www.nemlig.com/ but it is not as easy as I was used to, as the page I am trying to scrape things off is not static. What I am trying to do using Selenium is click this:

enter image description here

So that the zipcode pop-up is visible. Then, insert a number and hit enter.

This is my take on it:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

browser = webdriver.Chrome(executable_path=r"C:\Users\user\lib\chromedriver_77.0.3865.40.exe")
browser.get('https://www.nemlig.com/')

elem = browser.find_element_by_xpath("//div[@class='timeslot-statusbutton']")
elem.clear()
elem = browser.find_element_by_xpath("//input[@class='prompt__input ng-pristine ng-valid ng-empty ng-touched']")
elem.send_keys("2300")
elem.send_keys(Keys.RETURN)

But everything after browser.get returns me this error:

Traceback (most recent call last):

File "", line 8, in elem = browser.find_element_by_xpath("//div[@class='timeslot-statusbutton']").click()

File "D:\Anaconda3\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click self._execute(Command.CLICK_ELEMENT)

File "D:\Anaconda3\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute return self._parent.execute(command, params)

File "D:\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute self.error_handler.check_response(response)

File "D:\Anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace)

ElementNotInteractableException: element not interactable (Session info: chrome=77.0.3865.90)

How can I do this properly?

1
try click on the span css: .timeslot-statusbutton__text - Infern0
So I changed it to span[@class='timeslot-statusbutton__text'] and I am getting the same error. - Questieme
elem.clear() != elem.click() dont execute clear on a button, also do a check if the popup its not already open. find element by css .timeslot-prompt and check if have attribute disabled-hidden, means its not open. if it has means its already open no need to click. - Infern0
Yes. I figured the elem.clear() thing out eventually. Replaced it with browser.execute_script("arguments[0].click();", elem). Thanks for the tip about the pop-up! However, elem.send_keys("2300") is now not interactable. What do you think that is going wrong now? - Questieme
As i mention above, do safe check if the popup is already open or not! If the normal send text method is not working, send the text to the input using execute_script - Infern0

1 Answers

2
votes

You can try this code :

driver = webdriver.Chrome(executable_path = r'C:/Users/***/Downloads/BrowserDriver/chromedriver_win32/chromedriver.exe')
wait = WebDriverWait(driver,10)

driver.maximize_window()

driver.get("https://www.nemlig.com/")

wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".timeslot-prompt.initial-animation-done")))

wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[type='tel'][class^='pro']"))).send_keys('ABC')  

wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".btn.prompt__button"))).click()  

imports will be :

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