mirror of
https://github.com/Second-Hand-Friends/kleinanzeigen-bot.git
synced 2026-03-12 18:41:50 +01:00
Raise exception if special attribute could not be set
This commit is contained in:
@@ -11,7 +11,7 @@ from typing import Any, Final
|
|||||||
|
|
||||||
from overrides import overrides
|
from overrides import overrides
|
||||||
from ruamel.yaml import YAML
|
from ruamel.yaml import YAML
|
||||||
from selenium.common.exceptions import NoSuchElementException, TimeoutException
|
from selenium.common.exceptions import NoSuchElementException, TimeoutException, WebDriverException
|
||||||
from selenium.webdriver.common.by import By
|
from selenium.webdriver.common.by import By
|
||||||
from selenium.webdriver.support import expected_conditions as EC
|
from selenium.webdriver.support import expected_conditions as EC
|
||||||
|
|
||||||
@@ -405,27 +405,26 @@ class KleinanzeigenBot(SeleniumMixin):
|
|||||||
self.web_input(By.ID, "pstad-price", ad_cfg["price"])
|
self.web_input(By.ID, "pstad-price", ad_cfg["price"])
|
||||||
|
|
||||||
#############################
|
#############################
|
||||||
# set special properties of category
|
# set category specific attributes
|
||||||
#############################
|
#############################
|
||||||
if ad_cfg["special_attributes"]:
|
if ad_cfg["special_attributes"]:
|
||||||
LOG.debug('found %i special attributes', len(ad_cfg["special_attributes"]))
|
LOG.debug('Found %i special attributes', len(ad_cfg["special_attributes"]))
|
||||||
for special_property_key, special_property_value in ad_cfg["special_attributes"].items():
|
for special_attribute_key, special_attribute_value in ad_cfg["special_attributes"].items():
|
||||||
LOG.debug("trying to add special attribute %s: %s ", special_property_key, special_property_value)
|
LOG.debug("Setting special attribute [%s] to [%s]...", special_attribute_key, special_attribute_value)
|
||||||
try:
|
try:
|
||||||
self.web_select(By.XPATH, "//select[@id='" + special_property_key + "']", special_property_value)
|
self.web_select(By.XPATH, f"//select[@id='{special_attribute_key}']", special_attribute_value)
|
||||||
LOG.debug("Successfully set attribute field '%s': '%s' ", special_property_key, special_property_value)
|
except WebDriverException:
|
||||||
except BaseException:
|
LOG.debug("Attribute field '%s' is not of kind dropdown, trying to input as plain text...", special_attribute_key)
|
||||||
LOG.debug("attribute field '%s' is not of kind dropdown, trying to input as plain text ", special_property_key)
|
try:
|
||||||
try:
|
self.web_input(By.ID, special_attribute_key, special_attribute_value)
|
||||||
self.web_input(By.ID, special_property_key, special_property_value)
|
except WebDriverException:
|
||||||
LOG.debug("Successfully set attribute field '%s': '%s' ", special_property_key, special_property_value)
|
LOG.debug("Attribute field '%s' is not of kind plain text, trying to input as radio button...", special_attribute_key)
|
||||||
except BaseException:
|
try:
|
||||||
LOG.debug("attribute field '%s' is not of kind plain text, trying to input as radio button ", special_property_key)
|
self.web_click(By.XPATH, f"//*[@id='{special_attribute_key}']/option[@value='{special_attribute_value}']")
|
||||||
try:
|
except WebDriverException as ex:
|
||||||
self.web_click(By.XPATH, "//*[@id='" + special_property_key + "']/option[@value='" + special_property_value + "']")
|
LOG.debug("Attribute field '%s' is not of kind radio button.", special_attribute_key)
|
||||||
LOG.debug("Successfully set attribute field '%s': '%s' ", special_property_key, special_property_value)
|
raise NoSuchElementException(f"Failed to set special attribute [{special_attribute_key}]") from ex
|
||||||
except BaseException:
|
LOG.debug("Successfully set attribute field [%s] to [%s]...", special_attribute_key, special_attribute_value)
|
||||||
LOG.debug("attribute field '%s' is not of kind radio button. No more options. Wasn't able to set attribute ", special_property_key)
|
|
||||||
|
|
||||||
#############################
|
#############################
|
||||||
# set description
|
# set description
|
||||||
|
|||||||
@@ -283,6 +283,7 @@ class SeleniumMixin:
|
|||||||
|
|
||||||
:param timeout: timeout in seconds
|
:param timeout: timeout in seconds
|
||||||
:raises NoSuchElementException: if element could not be found within time
|
:raises NoSuchElementException: if element could not be found within time
|
||||||
|
:raises UnexpectedTagNameException: if element is not a <select> element
|
||||||
"""
|
"""
|
||||||
elem = self.web_await(EC.element_to_be_clickable((selector_type, selector_value)), timeout, NoSuchElementException)
|
elem = self.web_await(EC.element_to_be_clickable((selector_type, selector_value)), timeout, NoSuchElementException)
|
||||||
Select(elem).select_by_value(selected_value)
|
Select(elem).select_by_value(selected_value)
|
||||||
|
|||||||
Reference in New Issue
Block a user