M. ahmed
M. ahmed

Reputation: 45

driver.find_element_by_xpath does not click my element in selenium python

I have tried many ways but driver doesnot clicking my element.

done=driver.find_element_by_xpath("//button[@class='dimapply-btn']")
driver.execute_script("arguments[0].click();", done)

and I have also tried with WebDriverWait.

WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Done']"))).click()

I have also used (x,y) point.

done = driver.find_element_by_xpath('//body')
actions.move_to_element_with_offset(done, 320, 430).click().perform()

My html code is:

<div class="btn-apply" data-ng-click="applyDimensionChanges()" role="button" tabindex="0">
   <button class="dimapply-btn">Done</button>
</div>

It does not throws any errors. just passes by my code and does not click. please help me out. thank you in advance. i am solving this line for two days.

Upvotes: 1

Views: 1468

Answers (1)

undetected Selenium
undetected Selenium

Reputation: 193058

To click() on the element with text as Done button you can use either of the following Locator Strategies:

  • Using css_selector:

    WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"div.btn-apply[data-ng-click^='applyDimensionChanges']>button.dimapply-btn"))).click()
    
  • Using XPATH:

    WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//div[@class='btn-apply' and starts-with(@data-ng-click, 'applyDimensionChanges')]/button[@class='dimapply-btn' and text()='Done']"))).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
    

Upvotes: 1

Related Questions