From 4127fcc6d2266c26afc037a5d02d64b7f86df163 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Mon, 19 Aug 2019 11:17:01 +0200 Subject: digikey: o Checking that the URL changed after clicking a button. o Click the accept cookie button if found after navigating. --- src/ee/digikey/__init__.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/ee/digikey/__init__.py b/src/ee/digikey/__init__.py index b46ba85..e624db9 100644 --- a/src/ee/digikey/__init__.py +++ b/src/ee/digikey/__init__.py @@ -305,6 +305,7 @@ class DigikeyClient(object): form_input, form_button = find_form() if not form_input or not form_button: self.driver.get(self.baseurl) + self._accept_cookies() form_input, form_button = find_form() @@ -312,7 +313,13 @@ class DigikeyClient(object): raise EeException("Could not find form") form_input.send_keys(query) + + old_url = self.driver.current_url form_button.click() + new_url = self.driver.current_url + + if old_url == new_url: + raise EeException("Selenium error: clicked the button but the browser didn't navigate.") page = self.driver.page_source @@ -331,12 +338,18 @@ class DigikeyClient(object): self.on_download("Downloading {}".format(url)) self.driver.get(url) + self._accept_cookies() src = self.driver.page_source self.cache.save(cache_key, src) return src + def _accept_cookies(self): + cookie_blocker = self._find_first_visible("//div[@class='cookie-wrapper']//a[contains(@class, 'button')]") + if cookie_blocker is not None: + cookie_blocker.click() + def get_for_product_url(self, url, product_number): return self._req(url, "product-{}".format(product_number)) -- cgit v1.2.3