1

There are two "EXPORT" buttons on the web page I am testing. I am able to click the first using:

driver.find_element_by_xpath("//button[contains(.//text(),'EXPORT')]").click()

the driver then choses a dropdown and another div appears, again with an EXPORT button.

Div of second EXPORT elements

My code error when trying to execute:

driver.find_element_by_xpath("//button[contains(.//text(),'EXPORT')]").click()

for this element is:

selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element ... is not clickable at point (1824, 89). Other element would receive the click: ... (Session info: chrome=92.0.4515.107)

So it says it is unable to click the first EXPORT button and the second one would get the click. I've tried modifying my xpath expression to:

driver.find_element_by_xpath("//button[class()='MuiButtonBase-root MuiButton-root MuiButton-contained MuiButton-containedPrimary' and (.//text(),'EXPORT')]").click()

and a bunch of other attempts, but each time it is unable to locate. I want to be able to click the second EXPORT button (in the button class snippet shown in the pic).

1 Answer 1

2

You can differentiate between these two buttons with the help of xpath indexing.

Sample below :-

(//span[text()='EXPORT']/..)[1]

and for second button :-

(//span[text()='EXPORT']/..)[2]

and for this error

selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element ... is not clickable at point (1824, 89). Other element would receive the click: ... (Session info: chrome=92.0.4515.107)

I would suggest you to open browser in full screen mode when it's launched.

driver.maximize_window()

or probably, you can use ActionChain as well :-

from selenium.webdriver.common.action_chains import ActionChains
ActionChains(driver).move_to_element(driver.find_element(By.XPATH, "(//span[text()='EXPORT']/..)[2]")).click().perform()

Update 1 :-

You can use find_elements as well to store all the web element and then try to click the one you want.

all_export_button = driver.find_elements(By.XPATH, "//span[text()='EXPORT']/..")
#to click on first 
all_export_button[0].click()

#to click on Second 
all_export_button[1].click()
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks. I already have the window maximised. As for the indexing my error using: driver.find_element_by_xpath("//span[text()='EXPORT'][2]").click() is: selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//span[text()='EXPORT'][2]"} (Session info: chrome=92.0.4515.107)
Is Page URL public ? and I do see, you are using ("//span[text()='EXPORT'][2]") which looks incorrect, what I have suggested (see above is) (//span[text()='EXPORT']/..)[2] so you can use it like this driver.find_element_by_xpath("(//span[text()='EXPORT']/..)[2]").click()
Thank you, there's an alternative as well to do this, please see update 1 section above.

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.