2016-07-26 12 views
2

seleniumのボタン要素をpython 3に配置したいと考えています。私はいくつかの異なる方法を試みますが、すべて失敗しました。私は私の要素を見つけるためにXpathを使用しますが、それはより良い方法だ場合、私は知らない。セレン発見ボタン要素

これはHTMLコードです:

<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> 

この私はすでにパイソンにしてみてください何:

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

リターン:

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 
    

    リターン:

    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"}

    任意のアイデア?あなたはfind_element_by_id('place_order')

    を使用することができますxpathあなたは見つけることhereより多くの方法を見つけることができます使用したくない場合は感謝

    答えて

    1

    は、あなたはそれ

    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() 
    

    をクリックする前の要素に移動するActionChainsを使用することができます要素

    0

    クリックする前にこのボタンをスクロールしてください。

    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() 
    
    関連する問題