3
votes

I want to find a button element on a website with selenium on python 3 . I try some different method but all failed . I use Xpath to find my element but i don't know if it's the better method :

This is the HTML code :

<div id="review-buttons-container">
<div class="columns">
<div class="please-wait" id="review-please-wait" style="display:none;">

<span>PROCESSING...</span>
</div>
<input id="place_order" type="button" value="Complete Order" class="button end"/>
</div>
</div>

This what i already try on python :

br.find_element_by_xpath("//input[@id='place_order']").click()

return :

selenium.common.exceptions.WebDriverException: Message: unknown error: Element is not clickable at point (606, 678). Other element would receive the click :

  • ...
  • //div[@id='review-buttons-container']/div/input
    

    return :

    selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//div[@id='review-buttons-container']/div/input"}

    br.find_element_by_xpath("//form[2]/div[8]/div/input").click()
    

    selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//form[2]/div[8]/div/input"}

    Any idea ? thanks

    2

    2 Answers

    2
    votes

    You can use ActionChains to move to the element before clicking on it

    from selenium.webdriver.common.action_chains import ActionChains
    
    element = br.find_element_by_xpath("//input[@id='place_order']")
    ActionChains(br).move_to_element(element).perform() # I assume br is your webdriver
    element.click()
    

    If you don't want to use xpath you can use find_element_by_id('place_order')

    You can find here more ways to locate elements

    0
    votes

    Yo can try to scroll to this button before clicking using its location and js

    element = driver.find_element_by_id("place_order") 
    element_position = element.location["y"] 
    driver.execute_script("window.scroll(0, {})".format(element_position))
    time.sleep(1) #may not be required
    element.click()