1

Hey guys I am working on an automating bot for adding connections in LinkedIn, recently I encountered a problem for finding the "Connect" element(button) after searching in the search box and filtering for "People only".

That is the inspect of the relevant part:

<div id="ember374" class="ember-view">   
  <button id="ember378" class="artdeco-button artdeco-button--2 artdeco-button--secondary ember-view" data-control-name="entity_action_primary" data-control-id="AQT4G2UkQk6LQlbdf6XySw==">
    <!---->
    <span class="artdeco-button__text">Connect</span></button>

This is my tries for clicking on that "connect" element:

1. CONNECT_BUTTON_SEARCH_PAGE = "//*[contains(@class,'artdeco-button__text') and contains(.,'Connect')]"

2. CONNECT_BUTTON_SEARCH_PAGE = "//*[text()='Connect']"

3. CONNECT_BUTTON_SEARCH_PAGE = "//button[contains(. , ’Connect’)]"

WebDriverWait(self.driver, 5).until(EC.presence_of_element_located(
                        (By.XPATH, Xpath.CONNECT_BUTTON_SEARCH_PAGE))).click()

I have to mention that it works fine in the "Network" page, but I want it to add connections after searching a key word. So when I'm searching people according to a special key word, in that page I don't find the "Connect" button

I don`t know why but I can not reach for that element, appreciate if someone could help me

double-beep
  • 5,031
  • 17
  • 33
  • 41

2 Answers2

1

Finaly found a (weird) soulution with the help of @arundeepchohan.

First I used this xpath:

"//button/span[text()='Connect']/.."

But then I had to "refresh" the page before trying to click the "connect" button. I don't have an explanation for that to work and why it was necessary to refresh the page, but I used this part of code before the clicking method:

time.sleep(2)
self.driver.get(self.driver.current_url) 

Thanks for everyone who tried to help!

0

Try this xpath :

//button[contains(. , ’Connect’)]
YourHelper
  • 703
  • 7
  • 17