2

I want to click on "create post" button of this element:

<div class="l61y9joe j8otv06s a1itoznt qwtvmjv2 kiex77na lgsfgr3h mcogi7i5 ih1xi9zn ippphs35 a53abz89" data-hover="tooltip" data-tooltip-display="overflow" id="js_2f">Create Post</div>

But this id (id="js_2f") has a random value:

I did it this way but didn't work !

wait = WebDriverWait(self.browser, 20)
wait.until(EC.element_to_be_clickable((By.XPATH,  "//*[text()='Create Post' and contains(@id, 'js_')]"))).click()

How can i click on it Using Xpath method ?

4 Answers 4

1

Following should help:

driver.find_element_by_xpath('//div[contains(text(),"Create Post")]').click()
Sign up to request clarification or add additional context in comments.

Comments

0

You can try below xpath with contains

//div[contains(text(),'Create Post')]

2 Comments

please check again my post i did some changes, because there somethings i already did
Can you please share your url ? Also check if your element is not in the iframe. Would be great if you provide error information
0

You can try to perform a click on this element using link text

driver.find_element_by_link_text("Create Post")

or

driver.find_element_by_xpath("//div[text() = 'Create Post']")

6 Comments

please check again my post i did some changes, because there somthings i already did
provide the full error log, for understanding the problem
'File "C:/Users/jhon doe/PycharmProjects/FilesLibrary/AutomateFCB_INST.py", line 29, in upload_FCB wait.until(EC.element_to_be_clickable((By.XPATH, "//*[text()='Create Post' and contains(@id, 'js_')]"))).click() File "C:\Python37\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message: '
did you try the solutions which I mentioned in my answer? Please try and if the error still exists, provide this error only
I got this error for both selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"link text","selector":"Create Post"} ---------------------------- selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//div[contains(text(),"Create Post")]"}
|
0

The Create Post button is a JavaScript enabled element, so to click on the element you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[data-hover='tooltip'][data-tooltip-display]"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@data-hover='tooltip' and text()='Create Post'][@data-tooltip-display]"))).click()
    
  • Note : You have to add the following imports:

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

2 Comments

didnt work , i got this error message obj.upload_FCB() File "C:/Users/jhon doe/PycharmProjects/FilesLibrary/AutomateFCB_INST.py", line 31, in upload_FCB (By.XPATH, "//div[@data-hover='tooltip' and text()='Create Post'][@data-tooltip-display]"))).click() File "C:\Python37\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:
i got this error after some changes selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <div class="l61y9joe j8otv06s a1itoznt qwtvmjv2 kiex77na lgsfgr3h mcogi7i5 ih1xi9zn ippphs35 a53abz89" data-hover="tooltip" data-tooltip-display="overflow">...</div> is not clickable at point (277, 296). Other element would receive the click: <div class="_3ixn"></div>

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.