Selenium 2.53滚动太远 - 元素无法点击 - Python Firefox

时间:2016-08-31 11:15:14

标签: python selenium firefox

当我调用click方法时,Selenium向左滚动,因此元素不再可见。

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()
driver.get("http://www.simplelogistik.de/")

element = driver.find_element_by_name("plz_sender")
element.send_keys("04357")
element = driver.find_element_by_name("plz_target")
element.send_keys("10249")
element = driver.find_element_by_name("length")
element.send_keys("123")
element = driver.find_element_by_name("width")
element.send_keys("12")
element = driver.find_element_by_name("height")
element.send_keys("34")
element = driver.find_element_by_name("weight")
element.send_keys("5,6")
element = driver.find_element_by_xpath("//button[@type='submit'][@class='btn btn-lg btn-product right']")
element.click()

element = driver.find_element_by_id("price-dpd")
element.click()

所以我暂时使用黑客来缩小:

Action = webdriver.ActionChains(driver)   
body = driver.find_element_by_tag_name('body')
for i in range(2):
    Action.send_keys_to_element(body,Keys.CONTROL,"-").perform()

编辑: 在我调用click方法之前,它显示的元素。还尝试了" move_to_element"并等待。

webdriver.ActionChains(driver).move_to_element(element)
if element.is_displayed():
    wait.until(EC.visibility_of_element_located((By.ID, "price-dpd"))).click()

0 个答案:

没有答案