gpt4 book ai didi

python - Selenium 中的图像映射点击

转载 作者:行者123 更新时间:2023-12-01 09:06:27 26 4
gpt4 key购买 nike

我必须测试一个具有巨大图像的应用程序,但只有一小部分可以通过图像映射点击。

我已经尝试了一切来计算正确的位置并点击,但是点击超出了位置,测试失败。

有人可以告诉我如何记录当前鼠标位置或如何在测试期间显示鼠标吗?

我使用操作链将鼠标光标移动到图像的中心,但从那里我的所有计算都在图像映射矩形之外进行了单击。

请参阅下面的代码片段:

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

谢谢

最佳答案

仅供引用。我最终找到了解决方案。

# 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 的 get 操作,因此我将 href 放在 var 上,而不是费力地查找要单击的确切位置,然后对该 href 执行 get 操作。

脚本运行良好,甚至更好,它不依赖于屏幕分辨率。

关于python - Selenium 中的图像映射点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52007065/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com