0

Hello I'm trying to click on a button but it's not working for me what I have tried so far is as follows:

enter image description here

driver.find_elements_by_id("id__1115").click()
driver.find_elements_by_css_selector('.ms-Button.ms-Button--default.manageOwnersButtonStyle-1007').click()
driver.find_elements_by_xpath("/html[1]/body[1]/div[5]/div[1]/div[1]/div[1]/div[1]/div[3]/div[2]/div[3]/div[2]/div[1]/div[1]/div[1]/div[3]/button[1]/span[1]/span[1]/span[1]").click()
driver.find_elements_by_xpath("/html[1]/body[1]/div[5]/div[1]/div[1]/div[1]/div[1]/div[3]/div[2]/div[3]/div[2]/div[1]/div[1]/div[1]/div[3]/button[1]").click()

2 Answers 2

1

elements and click throwing error instead element and click because elements produce list and list is not clickable in selenium.

I changed my code to :

driver.find_element_

Only this xpath worked:

driver.find_element_by_xpath("/html[1]/body[1]/div[5]/div[1]/div[1]/div[1]/div[1]/div[3]/div[2]/div[3]/div[2]/div[1]/div[1]/div[1]/div[3]/button[1]/span[1]/span[1]/span[1]").click()

thanks

I don't how many elements. For example: (using xpath is better)

el = driver.find_elements_by_id("id__1115")
el[2].click()
Sign up to request clarification or add additional context in comments.

1 Comment

If others selection produce more than one then you can iterate or slicing then click
1

If Add owners text is not gonna change then

You can use the below xpath

//span[text()='Add owners']/ancestor::button

Click on it like

Code trial 1 :

time.sleep(5)
driver.find_element_by_xpath("//span[text()='Add owners']/ancestor::button").click()

Code trial 2 :

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Add owners']/ancestor::button"))).click()

Imports :

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

PS : Please check in the dev tools (Google chrome) if we have unique entry in HTML DOM or not.

Steps to check:

Press F12 in Chrome -> go to element section -> do a CTRL + F -> then paste the xpath and see, if your desired element is getting highlighted with 1/1 matching node.

Comments

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.