0

The structure looks like this:

<div class="edit-post-header">
<div class="edit-post-header__settings">
<button type="button" aria-disabled="false" class="components-button editor-post-publish-button editor-post-publish-button__button is-primary">Publish</button>
</div>
</div>

I am trying to click it like this:

browser.find_element_by_xpath("//div[@class='edit-post-header']//div[@class='edit-post-header__settings']//button[@class='editor-post-publish-button__button']").click()

But it does not work.

1
  • Any reason you want xpath explicitly? Why not query by CSS selector with class name, as the class looks quite specific? E.g. browser.find_element_by_css_selector('button.components-button.editor-post-publish-button.editor-post-publish-button__button.is-primary').click() Commented Oct 24, 2021 at 18:24

1 Answer 1

1

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.

xpath that you should check :

//button[text()='Publish']

if it is unique, please use below code to click :

Code trial 1 :

time.sleep(5)
driver.find_element_by_xpath("//button[text()='Publish']").click()

Code trial 2 :

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Publish']"))).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
Sign up to request clarification or add additional context in comments.

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.