简体   繁体   English

硒点击外部元素(按钮)

[英]Selenium Click Outside Element (button)

I'm running into the problem that I need to click on the expanded functions of an Element which is triggered by JS. 我遇到了一个问题,我需要单击由JS触发的Element的扩展功能。

Picture to illustrate the UI: http://imgur.com/LUyYOy8 用于说明用户界面的图片: http : //imgur.com/LUyYOy8

So when I hover over the blue button, it will display 3 other shapes at the bottom. 因此,当我将鼠标悬停在蓝色按钮上时,它将在底部显示其他3个形状。 Those shapes'html code won't show until mouse is hovering on it. 除非将鼠标悬停在它们上,否则这些shapes'html代码不会显示。 My approach was to use actions chain to hover over the blue button element then click off that element (in which way i can click on the 3 shapes below). 我的方法是使用动作链将鼠标悬停在蓝色按钮元素上,然后单击该元素(通过这种方式,我可以单击下面的3个形状)。

So far I have: 到目前为止,我有:

    Actions action = new Actions(driver);
    action.moveToElement(elementPosition).build().perform();
    action.moveToElement(elementPosition, offsetx, offxety).click();

But I cannot click Offset the element, is it a proper way to do it? 但是我无法单击“将元素偏移”,这是否是正确的方法? Thank you 谢谢

Are you able to retrieve the HTML code for the three buttons once you have made them visible? 使三个按钮可见后,您是否能够检索它们的HTML代码? If so, you should be able to find and click them using WebDriver.findElement() and WebElement.click() respectively. 如果是这样,您应该能够分别使用WebDriver.findElement()和WebElement.click()查找并单击它们。

For example: 例如:

// Find the blue button
WebElement blueButton = driver.findElement(By.id("blue"));
// Hover over the blue button
Actions action = new Actions(driver);
action.moveToElement(blueButton).build().perform();

// Find the red button
WebElement redButton = driver.findElement(By.id("red"));
// Click the red button
redButton.click();

// And so on...

In this example, it is imperative that you attempt to find the red button after the blue button has been hovered over. 在此示例中,当您将鼠标悬停在蓝色按钮上之后 ,您必须尝试找到红色按钮。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM