improve dropdown field handling

This commit is contained in:
sebthom
2023-05-16 18:28:23 +02:00
parent 40d6666213
commit 6f18fe9a0e

View File

@@ -617,6 +617,16 @@ class KleinanzeigenBot(SeleniumMixin):
LOG.debug('Found %i special attributes', len(ad_cfg["special_attributes"]))
for special_attribute_key, special_attribute_value in ad_cfg["special_attributes"].items():
LOG.debug("Setting special attribute [%s] to [%s]...", special_attribute_key, special_attribute_value)
try:
# if the <select> element exists but is inside an invisible container, make the container visible
select_container_xpath = f"//div[@class='l-row' and descendant::select[@id='{special_attribute_key}']]"
select_container = self.web_find(By.XPATH, select_container_xpath)
if not select_container.is_displayed():
self.web_execute(f"document.evaluate(\"{select_container_xpath}\"," +
" document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.style.display = 'block';")
except BaseException:
pass # nosec
try:
self.web_select(By.XPATH, f"//select[@id='{special_attribute_key}']", special_attribute_value)
except WebDriverException: