【问题标题】:Show current cursor coordinates in selenium python [duplicate]在 selenium python 中显示当前光标坐标 [重复]
【发布时间】:2021-07-06 20:09:59
【问题描述】:

我正在尝试在selenium中获取光标的当前坐标,主要是因为我想将它移动到一个元素,但是,非常重要,我不期待直接将它与动作链一起移动到元素,我希望它做一个平滑的轨迹,但要做到这一点,我需要了解:

  1. 能否获取当前光标位置来计算轨迹?

或者!!

  1. 有没有办法将“不知何故”生成的光标移动到元素的轨迹中?

注意:我不想要这个解决方案

webdriver.ActionChains(self.driver).move_to_element(element).click(
                element).perform()

我需要更类似于以下内容的东西:

def element_coordinates(e):
    location = e.location
    print(location)
    return location


e = WebDriverWait(self.driver, 5).until(
            EC.element_to_be_clickable((By.XPATH, '//div[contains(@label, "element")]')))
    
coordinates = element_coordinates(e)

为我提供特定元素的以下输出。以下是我想要的光标输出类型:

>>> {'y': 20, 'x': -65}

【问题讨论】:

标签: python python-3.x selenium selenium-webdriver


【解决方案1】:

我很久以前就使用过这种方法。在JAVA里看看能不能用python实现。

public int[] GetElementCoordinateWithId(String elementId) {
    int[] Location = new int[2];
    WebElement myElement = wait.until(ExpectedConditions.presenceOfElementLocated(By.id(elementId)));
    Point location = myElement.getLocation();
    Location[0] = location.getX();
    Location[1] = location.getY();
    System.out.println("Coordinates of an element is : " + Location[0] + " and " + Location[1]);
    return Location;
  }

如果您需要更多解释,请告诉我。

【讨论】:

  • 我有一个问题。如何获得“光标”元素?我知道如果我选择页面的一个元素,很容易得到那些坐标,但是对于光标是不同的
猜你喜欢
  • 2019-02-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多