【问题标题】:Selenium location method doesnt return the same type of coordinates for PyAutoGuiSelenium 定位方法不会为 PyAutoGui 返回相同类型的坐标
【发布时间】:2019-11-17 21:39:38
【问题描述】:

我不想使用 Selenium Actions 来使用 PyAutoGui。

过去我在使用 Java 时遇到过同样的问题,解决方案是在“Y”轴上添加偏移量,因为浏览器界面和 Windows 启动栏。现在我在“X”轴上也有偏移,尽管我使用最大化的铬。此外,每个元素都有不同的偏移量。

def move_mouse(xpath) :
    elem = driver.find_element_by_xpath(xpath)
    if elem.is_displayed() :
        x = elem.location.get('x')
        y = elem.location.get('y')
        print(x)
        print(y)
        pyautogui.moveTo(x,y,2)



chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--disable-infobars")
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get("https://www.python.org/")
driver.maximize_window()
print("Window Size : "+ str(driver.get_window_size()))
time.sleep(2)
print("Window Position : "+str(driver.get_window_position()))
move_mouse('//*[@id="downloads"]/a')

这是输出:

Window Size : {'width':1552, 'height': 840}

我的屏幕分辨率是 1920x1080,全屏模式的结果是一样的

Window Position : {'x' : -8, 'y': -8}

我不明白为什么窗口位置是负数

【问题讨论】:

    标签: python selenium pyautogui webautomation


    【解决方案1】:

    在使用“driver.maximize_window()”后我也有同样的情况希望它是正常的,如果你使用win +箭头到最大窗口,你会得到“更好”的结果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-22
      • 2020-08-01
      • 1970-01-01
      • 2018-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-05
      相关资源
      最近更新 更多