1

我可以使用 selenium web 驱动程序调整 web 元素的大小吗?如果这是可能的,我如何检查操作是否使用硒按预期工作。

感谢您的回答。

4

5 回答 5

1
public void Resize(IWebElement element, int offsetX, int offsetY = 0)
{   
    int width = element.Size.Width;            
    Actions action = new Actions(driver);
    action.MoveToElement(element, width, 1);
    action.ClickAndHold().MoveByOffset(offsetX, offsetY).Release();
    action.Build().Perform();            
}
于 2017-11-02T09:30:32.373 回答
0

我发现了以下内容:
- 拖放在 Selenium 中可以正常工作
- selenium 中的元素没有调整大小的方法
- 如果一个元素是可调整大小的,在我的情况下是一个框架,HTML 站点中有一个元素用于调整大小(该元素可能是不可见的,但如果您将鼠标移到它上面,鼠标光标会发生变化)
- 您只需识别此元素并对其执行拖放操作

于 2013-02-06T13:53:06.060 回答
0

我还必须使用 selenium 调整大小\dragAndDrop .. 所以经过一些研究后我发现了这个网站,它告诉你如何在没有 Js 的情况下调整大小:

WebElement resizeable = this.getDriver().findElement(By.cssSelector(" enter your selector, mine was div.resize"));

Action resize = action.clickAndHold(resizeable).moveByOffset(X offset, Y offset).release().build();

resize.perform();

我试过了,它奏效了。至于拖动,您可以使用:

Actions builder = new Actions(driver);

Action dragAndDrop = builder.clickAndHold(someElement)
   .moveToElement(otherElement)
   .release(otherElement)
   .build();

dragAndDrop.perform();

阿维诺姆

于 2015-02-24T17:13:32.857 回答
0

您可以在css中设置高度和宽度,然后使用

getCssValue(java.lang.String propertyName)

有关详细信息,请参阅http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/WebElement.html 。抱歉,我找不到任何示例代码!

雷切尔

于 2013-02-06T09:16:32.210 回答
0
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;

public class ResizeExample {
    WebDriver driver;

    @Test
    public void testToResizeElement() {

        driver = new FirefoxDriver();
        driver.manage().window().maximize();
        driver.navigate().to("http://jqueryui.com/resizable/");
        WebDriverWait wait = new WebDriverWait(driver, 5);
        wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.cssSelector(".demo-frame")));
        WebElement resizeableElement = driver.findElement(By.cssSelector(".ui-resizable-handle.ui-resizable-se.ui-icon.ui-icon-gripsmall-diagonal-se"));
        resize(resizeableElement, 50, 50);
    }

    public void resize(WebElement elementToResize, int xOffset, int yOffset) {
        try {
            if (elementToResize.isDisplayed()) {
                Actions action = new Actions(driver);
                action.clickAndHold(elementToResize).moveByOffset(xOffset, yOffset).release().build().perform();
            } else {
                System.out.println("Element was not displayed to drag");
            }
        } catch (StaleElementReferenceException e) {
            System.out.println("Element with " + elementToResize + "is not attached to the page document "  + e.getStackTrace());
        } catch (NoSuchElementException e) {
            System.out.println("Element " + elementToResize + " was not found in DOM " + e.getStackTrace());
        } catch (Exception e) {
            System.out.println("Unable to resize" + elementToResize + " - " + e.getStackTrace());
        }
    }

}
于 2018-01-15T05:55:50.673 回答