0

I'm trying to click on the Locations dropdown in LinkedIn. You'll reach this section of the LinkedIn page by searching for something in the LinkedIn Search bar and then clicking on 'People'.

enter image description here

This is the HTML element:

<button aria-checked="false" role="button" aria-label="Locations filter. Clicking this button displays all Locations filter options." 
id="ember745" class="artdeco-pill artdeco-pill--slate artdeco-pill--2 artdeco-pill--choice ember-view search-reusables__filter-pill-button" aria-controls="artdeco-hoverable-artdeco-gen-54" aria-expanded="false" data-control-name="filter_top_bar_select" type="button">  
      Locations
<!---->      <li-icon aria-hidden="true" type="caret-filled-down-icon" class="search-reusables__pill-button-caret-icon" size="small"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" data-supported-dps="16x16" fill="currentColor" class="mercado-match" width="16" height="16" focusable="false">
  <path d="M8 11L3 6h10z" fill-rule="evenodd"></path>
</svg></li-icon>
    
</button>

These are the different codes that I've tried till now. Mind you, I can't select by id because LinkedIn is changing the ember number ID every few minutes.

locations = browser.find_element_by_xpath('//*[@class="artdeco-pill artdeco-pill--slate artdeco-pill--2 artdeco-pill--choice ember-view search-reusables__filter-pill-button"]')
locations = browser.find_element_by_xpath('//div[@aria-label="Locations filter. Clicking this button displays all Locations filter options."]')
locations = browser.find_element_by_xpath("//div[@aria-label='Locations filter. Clicking this button displays all Locations filter options.']/div[@class='artdeco-pill artdeco-pill--slate artdeco-pill--2 artdeco-pill--choice ember-view search-reusables__filter-pill-button' and text()='Locations']")
locations = browser.find_element_by_xpath('(//div[@class="artdeco-pill artdeco-pill--slate artdeco-pill--2 artdeco-pill--choice ember-view search-reusables__filter-pill-button"])[3]')
locations = WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.CLASS_NAME, 'artdeco-pill artdeco-pill--slate artdeco-pill--2 artdeco-pill--choice ember-view search-reusables__filter-pill-button')))

I've spent a lot of time on this but haven't found a solution yet.

After clicking on Location, I also want to select United States and then click on Company Name and write a company name.


Next part: This is the html for 'United States' location. I want to click on 'United States' and search for that filter.

<li class="search-reusables__collection-values-item">
        <input aria-label="Filter by United States" name="United States" id="geoUrn-103644278" class="search-reusables__select-input" data-control-name="filter_detail_select" type="checkbox" value="103644278">
        <label for="geoUrn-103644278" class="search-reusables__value-label">
          <p class="display-flex">
            <span class="t-14 t-black--light t-normal">
              United States
            </span>
          </p>
        </label>
<!---->      </li>

I tried this code but it didn't do anything:

unitedstates = WebDriverWait(browser, 10).until(EC.visibility_of_element_located((By.XPATH, '//li//input[contains(@aria-label,"Filter by United States")]')))
unitedstates.click()

1 Answer 1

1

That specific button can be located with this XPath:

//span//button[contains(@aria-label,'Locations filter')]

So the element can be retrieved by

locations_btn = WebDriverWait(browser, 10).until(EC.visibility_of_element_located((By.XPATH, '//span//button[contains(@aria-label,"Locations filter")]')))

The "United States" location can be selected by

WebDriverWait(browser, 10).until(EC.visibility_of_element_located((By.XPATH, '//div[contains(@id,"locations-filter")]//li[@class="search-reusables__collection-values-item"]//span[contains(.,"United States")]'))).click()

Or if you want to click the checkbox you can use something like this:

WebDriverWait(browser, 10).until(EC.visibility_of_element_located((By.XPATH, '//div[contains(@id,"locations-filter")]//li[@class="search-reusables__collection-values-item" and .//span[contains(.,"United States")]]//input'))).click()
Sign up to request clarification or add additional context in comments.

14 Comments

Thanks @Prophet. Can you write the entire statement of the code?
what do you mean?
I mean writing the full code for the above statement like: browser.find_element_by_xpath...etc
is this what you are asking for? The updated answer
Thanks! Can you help me with one more thing. I want to select United States as a location. How should I select that? I'll paste the html for that in the question.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.