简体   繁体   中英

Selenium window scroll works only in Debug mode identifying Select element using Selenium and Python

I'm scraping a VUE.js website and when I have debug mode turned on in Selenium it can locate and click a drop down button but when I run it in normal mode it throws the following error message:

selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <select id="sortselectbox" data-ph-at-id="search-page-sort-drop-down" class="form-control au-target" value.bind="searchParams.sortBy" change.delegate="sortfilterSearch()" tabindex="0" data-ph-id="ph-page-element-page20-4VGGDW" au-target-id="169">...</select> is not clickable at point (707, 444). Other element would receive the click: <div class="chatBotNotificationText" tabindex="0">...</div>
  (Session info: headless chrome=96.0.4664.110)

Here's how I'm finding the dropdown button

Order = driver.find_element_by_xpath("//*[@id='sortselectbox']")

Before that here's how I scroll to the top of the website so that the sortselectbox become visible for the driver

driver.execute_script("window.scrollTo(0, 220)") #Page up

Here's the HTML element

<select id="sortselect" data-ph-at-id="search-page-sort-drop-down" class="form-control au-target" value.bind="searchParams.sortBy" change.delegate="sortfilterSearch()" tabindex="0" data-ph-id="ph-page-element-page20-UCZFWs" au-target-id="150"> <option value="Most relevant" key="c-internal-digital-technology-it-53pxnB-ph-search-results-v2-view4-mostRelevantText" data-ph-id="ph-page-element-page20-srcQGN"> Most relevant </option> <option value="Most recent" key="c-internal-digital-technology-it-53pxnB-ph-search-results-v2-view4-mostRecentText" data-ph-id="ph-page-element-page20-Br2Xo6"> Most recent </option> </select>

I've tried adding more sleep before and after the scroll but it seems it's failing at that step. All signs are indicating that scrolling doesn't work in normal mode. Would I have to find another way locating that sortselectbox button without the use of the window.scrollTo script?

Thanks!

This error message...

selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <select id="sortselectbox" data-ph-at-id="search-page-sort-drop-down" class="form-control au-target" value.bind="searchParams.sortBy" change.delegate="sortfilterSearch()" tabindex="0" data-ph-id="ph-page-element-page20-4VGGDW" au-target-id="169">...</select> is not clickable at point (707, 444). Other element would receive the click: <div class="chatBotNotificationText" tabindex="0">...</div>

...implies that the click attempt to the element is obstructed by the chatBotNotification .

As the desired item is a Select element ideally to select an option you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies :

  • Using CSS_SELECTOR :

     Select(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "select#sortselect[data-ph-at-id='search-page-sort-drop-down']")))).select_by_value("Most relevant")
  • Using XPATH :

     Select(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//select[@id='sortselect' and @data-ph-at-id='search-page-sort-drop-down']")))).select_by_value("Most recent")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM