pythonseleniumselenium-webdriveriframewebdriverwait

Message: no such element: Unable to locate element Selenium Python


I am trying to click on a button but getting this error message: The element I am trying to click does exist on the page but I am not sure why it's saying that the element does not exist:

Message: no such element: Unable to locate element: {"method":"xpath","selector":"//button[@class="vote_button mfp-voteText"]"}

Below is my code:

driver.get('https://trupanion.com/canada/members/contest?pixlee_album_photo_id=427049511')

time.sleep(10)

try:
    vote = driver.find_element_by_xpath('//button[@class="vote_button mfp-voteText"]')
    vote.click()
except Exception as e:
    print(e)

Below is the XPath in chrome dev tool which shows it's correct:

enter image description here


Solution

  • The desired element is within an <iframe> so you have to:

    VOTED


    Reference

    You can find a couple of relevant discussions in: