1

I am trying to click show results button after selecting filter on linkedin. I have correctly found the button element but it is giving me this error:

selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable: [object HTMLDivElement] has no size and location

Here is my piece of code that I have tried:

element = WebDriverWait(self, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, 'div[class="artdeco-hoverable-content__shell"]')))                
box = self.find_element_by_css_selector('div[class="artdeco-hoverable-content__shell"]')
ele = box.find_element_by_css_selector('button[data-control-name="filter_show_results"]')
        
ActionChains(self).move_to_element(ele).click(ele).perform()

I have also tried:

self.execute_script("arguments[0].click();", ele)

What's the reason behind this?

HTML of the results button:

<div class="reusable-search-filters-buttons display-flex justify-flex-end mt3 ph2">
      <button data-test-reusables-filter-cancel-button="true" data-control-name="filter_pill_cancel" aria-label="Cancel Locations filter" id="ember429" class="artdeco-button artdeco-button--muted artdeco-button--2 artdeco-button--tertiary ember-view" type="button"><!---->
<span class="artdeco-button__text">
    Cancel
</span></button>
      <button data-test-reusables-filter-apply-button="true" data-control-name="filter_show_results" aria-label="Apply current filter to show results" id="ember430" class="artdeco-button artdeco-button--2 artdeco-button--primary ember-view ml2" type="button"><!---->
<span class="artdeco-button__text">
    Show results
</span></button>
  </div>

Edit 2: Here is the image of the button , I am trying to click. https://ibb.co/4Y7VN0j

Edit 3: Image with dev tools open : https://ibb.co/CJdtNM1

glitch_123
  • 139
  • 12
  • can you post a screenshot with dev tools open and element (and parent elements expanded in dev tools? – Barry the Platipus Jul 30 '22 at 10:08
  • @platipus_on_fire Please read why a [screenshot of HTML or code or error is a bad idea](https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors). Consider suggesting OP to update the Question with formatted text based relevant HTML, code trials and error stack trace. – undetected Selenium Jul 30 '22 at 10:28
  • That html page is behind a login, there is no way I can see it without logging in (which I don't want to). The only other way would be for OP to screenshot it and uploading to some img serving service. I'm still waiting for that. – Barry the Platipus Jul 30 '22 at 10:30
  • 1
    @platipus_on_fire _there is no way I can see it without logging_: You won't ever want to do that either, do you? It's impossible to visit 100's of websites from 100's of question to understand OP's actual usecase. That's why _text based relevant HTML_ is the minimal requirement. – undetected Selenium Jul 30 '22 at 10:34
  • @glitch_123 I cannot meaningfully answer it without a screenshot: is that element in view? is there some cookie accept overlay over it? is there some sort of fixed nav/element blocking the click? is the button and its parent enclosed in someother element with display:none? If you don;t want to provide a printscreen, try scrolling to the element with javascript ('arguments[0].scrollIntoView();', element). Try using `location_once_scrolled_into_view`, which also brings the element into view. I cannot offer more than generic advice without a clear printscreen of both dev tools and page. – Barry the Platipus Jul 30 '22 at 10:49
  • @platipus_on_fire I have updated the image. The button already remains in the view. – glitch_123 Jul 31 '22 at 09:19
  • That's great, but I was hoping you also open Dev tools, and I can see side by side page and structure (expanded around that element of course). – Barry the Platipus Jul 31 '22 at 10:09
  • @platipus_on_fire I have updated the image . Please check now – glitch_123 Jul 31 '22 at 11:06
  • Ok - I will try to respond as a comment: first of, try sending a click() in 'Add a location' search box (locate it with webdrivertwait(..) and then .click(), no Actionchains. After that, try to locate that search button and click it directly with `WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[data-control-name='filter_show_results'][id='ember472']"))).click()`. Let me know if it worked. – Barry the Platipus Jul 31 '22 at 11:15
  • it did not work. raised Timeout Exception – glitch_123 Jul 31 '22 at 11:24
  • What happened after you clicked that search location field? Try printing in terminal every step, i.e print ('clicked the search field' after clicking, and then give it a timeout of 2 seconds: time.sleep(5). Are you able to select different countries in that dropdown, I mean, to click on those checkboxes? Sorry, I don;t have a linkedin account, so I cannot test it properly. – Barry the Platipus Jul 31 '22 at 11:34
  • I have this problem too. – Sridhar Sarnobat Jul 25 '23 at 05:13

1 Answers1

0

The desired element is a Ember.js enabled element, so to click on the Show results button instead of presence_of_element_located() you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[data-control-name='filter_show_results'][aria-label='Apply current filter to show results'] span.artdeco-button__text"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@data-control-name='filter_show_results' and @aria-label='Apply current filter to show results']//span[contains(., 'Show results')]"))).click()
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352