0

Here is the element I am trying to click on for an automated program using Selenium:

<input id="btnNextWeek" title="Next Week" onclick="if (this.className != 'mybtndis2') { moveweek(7) }" type="button" value=">>" name="btnNextWeek" class="mybtn2" style="-webkit-appearance: button; padding-left: 8px; padding-right: 8px; height: auto">

Getting this error:

Message: no such element: Unable to locate element: {"method":"xpath","selector":"//input[@title="Next Week"]"} (Session info: chrome=83.0.4103.116)

This is the code that gives the error:

self.driver.find_element_by_xpath("//input[@title=\"Next Week\"]")\
.click()

Any suggestions?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
rm15
  • 3
  • 2
  • Consider using code fences for the elements and responses. This will make your question a lot more readable. This can be accomplished easily by selecting text and clicking the associated buttons on top in the editor. – H.Hasenack Jul 03 '20 at 19:50

3 Answers3

0

Use this - driver.find_element_by_xpath('//input[@title="Next Week"]').click()

This will work.Always if you are using double quotes inside use single quote before to get rid of the escaping and we dont need to escape the . before click() because here . is used to call a method.

Thanks.

Surya_1897
  • 97
  • 9
0

The desired element 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.mybtn2#btnNextWeek[title='Next Week'][name='btnNextWeek']"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='mybtn2' and @id='btnNextWeek'][@title='Next Week' and @name='btnNextWeek']"))).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
    

References

You can find a couple of relevant discussions on no such element in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Didn't work for some reason. Just timing out after 20 seconds. Appreciate you trying to help though! – rm15 Jul 05 '20 at 02:47
0

It could be the element cannot be found because it is inside an iframe... if so then you could use

frame = driver.find_element_by_xpath('insert frame xpath')
driver.switch_to.frame(frame)
driver.find_element_by_xpath('//input[@title="Next Week"]').click()
driver.switch_to.default_content()
Bacon
  • 1