I am using the xpath selector for the button itself and selenium gives me an error selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="ember1355"]/button"} when I try to click. What I am trying to do is use selenium to connect with people in linkedin. When I search for a specific term, then I want to pull out all the profiles that say "Connect" and click on the each button. The html is
<div class="search-result__actions">
<div id="ember3093" class="ember-view">
<button aria-label="Connect with Persons name" class="search-result__actions--primary button-secondary-medium m5" data-control-name="srp_profile_actions" data-ember-action="" data-ember-action-3096="3096">Connect</button>
<div id="ember3099" class="ember-view"><div id="ember3100" class="ember-view"><!----></div></div>
</div>
</div>
and my code is:
if each.find('div', class_='search-result__actions').find('div').text.strip() == "Connect":
id = each.find('div', class_='search-result__actions').find('div')['id']
id = '//*[@id="'+id+'"]'
print(id)
#this is where the code isn't working
driver.find_element_by_xpath('//*[@id="ember1355"]/button').click()