0

I am trying to click to an object that I select with Xpath, but there seems to be problem that I could not located the element. I am trying to click accept on the page's "Terms of Use" button. The code I have written is as

    driver.get(link)
    
    accept_button = driver.find_element_by_xpath('//*[@id="terms-ok"]')
    accept_button.click()
    
    prov = driver.find_element_by_id("province-region")
    prov.click()

Here is the HTML code I have:

enter image description here

And I am getting a "NoSuchElementException". My goal is to click this "Kabul Ediyorum" button at the bottom of the HTML code. I started to think that we have some restrictions on the tasks we could do on that page. Any ideas ?

1 Answers1

1

Not really sure what the issue might be.
But you could try the following:

  1. Try to locate the element by its visible text
accept_button = driver.find_element_by_xpath("//*[text()='Kabul Ediyorum']").click()
  1. Try with ActionChains

For that you need to import ActionChains

from selenium.webdriver.common.action_chains import ActionChains

accept_button = driver.find_element_by_xpath("//*[text()='Kabul Ediyorum']")
actions = ActionChains(driver)
actions.click(on_element=accept_button).perform()

Also make sure you have implicitly wait

# implicitly wait
driver.implicitly_wait(10)

Or explicit wait

element = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//*[text()='Kabul Ediyorum']"))).click()

Hope this helped!

Herker
  • 552
  • 6
  • 20