【问题标题】:How to do Resize using Java and Selenium?如何使用 Java 和 Selenium 调整大小?
【发布时间】:2023-03-20 08:15:01
【问题描述】:

如何使用 Java 和 Selenium 调整大小?

Link

我一直在尝试的代码:

   public static void main(String[] args) throws InterruptedException 
    {
        WebDriverManager.chromedriver().setup();
        WebDriver driver = new ChromeDriver();
        driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(10));
        
        
        driver.get("https://jqueryui.com/resizable/");
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
        driver.switchTo().frame(0);
        Thread.sleep(2000);
        WebElement resize = driver.findElement(By.xpath("//div[@id = 'resizable']/div[3]"));
        //WebElement resize = driver.findElement(By.id("resizable"));
        new Actions(driver).dragAndDropBy(resize, 400, 400).perform();
    }

这是以下错误:

> Exception in thread "main"
> org.openqa.selenium.interactions.MoveTargetOutOfBoundsException: move
> target out of bounds

【问题讨论】:

  • 您只能在外部矩形内调整内部矩形的大小。首先获取外部矩形的边界,然后查看可以调整内部矩形大小的可能值。
  • 我可以得到以下答案的一些更新吗?

标签: java selenium selenium-webdriver selenium-chromedriver resize


【解决方案1】:

你之前分享的代码,我做了一些改动,请看下面的代码。

网页元素在 iframe 中,因此我们必须先切换到 iframe,然后使用具有以下属性的操作类 dragAndDropBy

(WebElement source, int xOffset, int yOffset)

代码:

driver.manage().window().maximize();
//driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
driver.get("https://jqueryui.com/resizable/");
Actions action = new Actions(driver);
WebDriverWait wait = new WebDriverWait(driver, 30);

wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.cssSelector("iframe.demo-frame")));
WebElement resizeButton = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.ui-icon-gripsmall-diagonal-se")));
action.dragAndDropBy(resizeButton, 100, 50).build().perform();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-22
    • 2010-10-07
    • 2017-11-07
    • 2013-06-24
    • 1970-01-01
    • 2014-02-20
    • 2010-09-27
    相关资源
    最近更新 更多