2017-06-13 35 views
0

目前,硒的Actions類只有以此爲moveToElement功能:Selenium - 如何懸停在具有雙/浮點座標的點上?

public Actions moveToElement(WebElement toElement, int xOffset, int yOffset { 
    action.addAction(new MoveToOffsetAction(mouse, (Locatable) toElement, xOffset, yOffset)); 
    return this; 
} 

然而,該網站的座標有float座標(例如(200.5,0))。有什麼辦法可以徘徊在這個特定的地方嗎?

[編輯]: 這是我正在嘗試做的方法。工程與整數完美的罰款座標

public void hoverPt(String xAxis) throws Exception //Use Build Interaction 
{ 
int x = Integer.parseInt(xAxis); 
WebDriver driver = WebManager.getDriver(); 
WebElement lineGraph = driver.findElement(By.xpath("[xpath of chart plane]")); 
Actions builder = new Actions(driver); 
builder.moveToElement(lineGraph, x, 0).build().perform(); 
Thread.sleep(5000); 
} 

字符串X軸是獲取從一個Excel工作表,然後我就分析它來詮釋,所以我可以將其參數來moveToElement

+0

你能考慮更新我們的工作,具體步驟以及相關的HTML DOM嗎?謝謝 – DebanjanB

+0

@DebanjanB編輯了問題 –

+0

我有一個答案,但在提供解決方案之前,我需要檢查它是否正常工作。你能否給我一個演示URL /鏈接來驗證我的答案?謝謝 – DebanjanB

回答

0

可以使用機器人類這樣的:

Point p = toElement.getLocation(); 
    int x = p.getX(); 
    int y = p.getY(); 
    Dimension d = toElement.getSize(); 
    int h = d.getHeight(); 
    int w = d.getWidth(); 
    Robot r = new Robot(); 
    r.mouseMove(x + (w/2), y+(h/2) +80);