我必须测试一个具有巨大图像的应用程序,但是只有一小部分可以通过图像映射单击。
我已经尝试了所有方法来计算正确的位置并单击,但是单击不在位置上,因此测试失败。
有人可以指出我如何记录当前的鼠标位置或在测试过程中如何显示鼠标吗?
我正在使用动作链将鼠标光标移动到图像的中心,但是从那里开始,我所有的计算都使点击位置超出了图像映射矩形。
请参见下面的代码段:
el=driver.find_elements_by_xpath("/html/body/form/table/tbody/tr/td/img")[0]
#el=driver.find_elements_by_xpath("//html/body/map/area[2]")[0]
width=el.size["width"]
height=el.size["height"]
action = webdriver.common.action_chains.ActionChains(driver)
action.move_to_element(el)
print driver.get_window_position()
action.move_by_offset(193, 310)
print driver.get_window_position()
action.click()
action.perform()
谢谢
答案 0 :(得分:1)
仅供参考。我最终找到了解决方案。
# Wait for the map to show up and navigate to account page
try:
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "Map")))
except Exception, e:
print "Image with token toot long to load..."
raise AssertionError()
href = driver.find_element_by_xpath("//html/body/map/area[2]").get_attribute("href")
driver.get(href)
我可以看到点击只会将获取的内容发送到HREF,因此我没有费力找到确切的点击位置,而是将href放在变量上,然后对该href进行获取。
脚本运行良好,甚至更好,它与屏幕分辨率无关。
答案 1 :(得分:0)
您尝试使用javascript单击吗?
driver.execute_script("arguments[0].click();", element)