1

I'm testing my web scraping skills with Python and Selenium and I found an button with a changing "id" "ember" and the numbers change everytime. Everything else is the same as all buttons. The only thing that's unqiue is

<button aria-label="View only People results" id="ember697" class="search-vertical-filter__filter-item-button artdeco-button artdeco-button--muted artdeco-button--2 artdeco-button--tertiary ember-view" type="button"><!---->
<span class="artdeco-button__text">
    People
</span></button>

I've tried all the methods so far (i.e., id, CSS_selector, xpath, etc.).
[![Linked In button][1]][1]

Here's the error I keep getting no matter what I select.

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element
5
  • 1
    So, do you want to search by aria-label, class, or something else? Commented Mar 8, 2020 at 23:41
  • 1
    What is the issue, then? Commented Mar 8, 2020 at 23:42
  • @AyushGarg, yes please. I don't know how to do that. Commented Mar 9, 2020 at 0:06
  • @AMC, I edited the original post. I get a no such element exception error. Commented Mar 9, 2020 at 0:07
  • @BrandonJacobson Please provide the entire error message, as well as a minimal reproducible example. Commented Mar 9, 2020 at 0:35

2 Answers 2

2

So, since you want to search through aria-label, you can use an XPATH:

driver.find_elements_by_xpath("//button[@aria-label='View only People results']")

EDIT: You could also use a css selector like this:

driver.find_elements_by_css_selector("button[aria-label='View only People results'']")
Sign up to request clarification or add additional context in comments.

1 Comment

The xpath suggestion worked. When I hit inspect, then copy xpath, it doesn't give me the syntax you provided. I guess I have to learn more about Selenium's syntax. Thanks!!!
2

Try this: option1 - i am assuming ember will be there and only numbers are changing

driver.find_elements_by_xpath("//*[starts-with(@id, 'ember')]")

option 2-

driver.find_elements_by_xpath("//*[contains(@id, 'ember')")

option 3-

driver.find_elements_by_xpath("//*[contains(@class, 'search-vertical-filter__filter-item-button')")

Hope it helps you.

1 Comment

So, there are multiple buttons with the ember id. I didn't know you can do "starts-with" though. Thank you so much. I guess I still have more to learn about the Selenium syntax.

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.