0

I made linked in connecting script but he is clicking on my class button now my error is how to click on all connect button?

how can I click on all connect button?

here is my code:

#search

click_search = WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.XPATH, "/html[1]/body[1]/header[1]/div[1]/form[1]/div[1]/div[1]/div[1]/artdeco-typeahead-deprecated[1]/artdeco-typeahead-deprecated-input[1]/input[1]"))).send_keys("pyt")
time.sleep(.2)
click_search = WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.XPATH, "/html[1]/body[1]/header[1]/div[1]/form[1]/div[1]/div[1]/div[1]/artdeco-typeahead-deprecated[1]/artdeco-typeahead-deprecated-input[1]/input[1]"))).send_keys("hon")
time.sleep(.2)
click_search = WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.XPATH, "/html[1]/body[1]/header[1]/div[1]/form[1]/div[1]/div[1]/div[1]/artdeco-typeahead-deprecated[1]/artdeco-typeahead-deprecated-input[1]/input[1]"))).send_keys(Keys.ENTER)
click_people = WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.XPATH, "/html[1]/body[1]/div[5]/div[7]/div[4]/div[1]/div[1]/header[1]/div[1]/div[1]/div[1]/ul[1]/li[1]/button[1]/span[1]"))).click()
click_connect = WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.XPATH, "/html[1]/body[1]/div[5]/div[7]/div[4]/div[1]/div[2]/div[1]/div[2]/div[1]/div[1]/div[1]/div[1]/ul[1]/li[4]/div[1]/div[1]/div[3]/div[1]/button[1]"))).click()
click_done = WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.XPATH, "/html[1]/body[1]/div[5]/div[8]/div[1]/div[1]/div[1]/section[1]/div[1]/div[2]/button[2]"))).click()
2
  • So... where is your error? Commented Jul 31, 2019 at 10:57
  • How can I click on all connect button Commented Jul 31, 2019 at 11:53

1 Answer 1

1

Using absolute XPath locators is not the best idea as it makes them very fragile and sensitive to any DOM change

The recommended locator strategy is using ID where possible, however when IDs are absent or dynamic it's better to come up with an alternative way.

For example you can stick to button text.

Compare your XPath expression for People:

/html[1]/body[1]/div[5]/div[7]/div[4]/div[1]/div[1]/header[1]/div[1]/div[1]/div[1]/ul[1]/li[1]/button[1]/span[1]

with this one:

//span[text()='People']

And both expressions are basically matching the same element:

enter image description here

So you can fetch all Connect buttons using find_elements_by_xpath() function like:

connect_buttons = driver.find_elements_by_xpath("//button[text()='Connect']")

for connect_button in connect_buttons:
    print(connect_button.get_attribute("aria-label"))

References:

Sign up to request clarification or add additional context in comments.

4 Comments

error: Traceback (most recent call last): File ".\linked_conecting_script.py", line 93, in <module> for connect_button in connect_buttons: TypeError: 'NoneType' object is not iterable
use find_elements_by_xpath function
still getting when he click on connect button and giving a traceback error
Bro Now How Can I click on the done button because when he click on connect button getting traceback error

Your Answer

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