2

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

13
  • Why didn´t you select by Id?
    – Carol
    CommentedOct 2, 2020 at 18:34
  • Because it's changing by every person. Am I wrong?CommentedOct 2, 2020 at 18:39
  • So how do i am implement that? @arundeepchohanCommentedOct 2, 2020 at 21:09
  • The first implementation didnt work. The second, should i put this after the "//*span[text()='Connect'] ? sry but im not know much about this preceding sibling @arundeepchohanCommentedOct 2, 2020 at 21:26
  • Thanks man but still does`nt work. Any other ideas? u can see the edited html @arundeepchohanCommentedOct 2, 2020 at 21:34

2 Answers 2

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’)] 
    4
    • Thanks but it does`nt work. any other ideas? @YourHelperCommentedOct 2, 2020 at 21:22
    • Actually there is no way if the button contains this asa text what is the error?CommentedOct 2, 2020 at 21:41
    • nothing happens. its keep progressing in my code and doesnt find the element(wo`nt click on the "connect") button @YourHelperCommentedOct 2, 2020 at 21:48
    • Instead of the click() method try this : sendKeyd(Keys,ENTER); to the xpath that I mentioned beforeCommentedOct 3, 2020 at 12:52

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.