From 719d40cc5bfe1ea8aec4039b8ac30b5ba0abd4f6 Mon Sep 17 00:00:00 2001 From: Airwave1981 <32637309+Airwave1981@users.noreply.github.com> Date: Wed, 15 Feb 2023 09:15:29 +0100 Subject: [PATCH] Fixed #155 sell directly Sell directly was not handled correctly. --- kleinanzeigen_bot/__init__.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/kleinanzeigen_bot/__init__.py b/kleinanzeigen_bot/__init__.py index 6c7528b..54d9959 100644 --- a/kleinanzeigen_bot/__init__.py +++ b/kleinanzeigen_bot/__init__.py @@ -502,11 +502,15 @@ class KleinanzeigenBot(SeleniumMixin): # set sell_directly ############################# sell_directly = ad_cfg["sell_directly"] - if sell_directly and ad_cfg["shipping_type"] == "SHIPPING" and ad_cfg["shipping_options"] and price_type in {"FIXED", "NEGOTIABLE"}: - try: - self.web_click(By.XPATH, '//*[contains(@class, "BuyNowSection")]//span[contains(@class, "Toggle--Slider")]') - except NoSuchElementException as ex: - LOG.debug(ex, exc_info = True) + try: + if sell_directly and ad_cfg["shipping_type"] == "SHIPPING" and ad_cfg["shipping_options"] and price_type in {"FIXED", "NEGOTIABLE"}: + if not self.webdriver.find_element(By.ID, "buy-now-toggle").is_selected(): + self.web_click(By.XPATH, '//*[contains(@class, "BuyNowSection")]//span[contains(@class, "Toggle--Slider")]') + else: + if self.webdriver.find_element(By.ID, "buy-now-toggle").is_selected(): + self.web_click(By.XPATH, '//*[contains(@class, "BuyNowSection")]//span[contains(@class, "Toggle--Slider")]') + except NoSuchElementException as ex: + LOG.debug(ex, exc_info = True) ############################# # set description