简体   繁体   English

如何用硒驱动器减少表中的列宽

[英]How to reduce column width in table with selenium driver

I am automating one functionality on certain website where I want to resize the column 'Description' of table, but while doing same with below mentioned code, getting some kind of warning or error and same is not happening. 我正在某个网站上自动化一个功能,我希望调整表格的“描述”列,但是在对下面提到的代码执行相同操作时,会发生某种警告或错误并且不会发生同样的情况。

//This is Description column for which I want to change the width //这是我想要更改宽度的描述列

    WebElement descr = driver.findElement(By.linkText("Description"));

    WebDriverWait wait = new WebDriverWait(driver, 25);
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("Description")));

    int width_descr = descr.getSize().getWidth();
    int height_descr = descr.getSize().getHeight();
    System.out.println("Width of Description ="+width_descr);
    System.out.println("Height of Description ="+height_descr);

    int half_height_descr= height_descr/2;
    System.out.println("Half of Height of Description ="+half_height_descr);

    //Logger.getLogger("org.openqa.selenium").setLevel(Level.SEVERE);

    Actions builder = new Actions(driver);

    Action resizable = builder
            .moveToElement(descr, width_descr, height_descr)
            .clickAndHold()
            .moveByOffset(width_descr, 0)
            .release()
            .build();

    resizable.perform();

}

Actual output as below:- 实际产量如下: -

Width of Description =242
Height of Description =27
Half of Height of Description =13

Apr 01, 2019 8:35:54 PM org.openqa.selenium.interactions.Actions moveToElement 2019年4月1日8:35:54 org.openqa.selenium.interactions.Actions moveToElement

INFO: When using the W3C Action commands, offsets are from the center of element--This is the warning i am getting in console. 信息:当使用W3C Action命令时,偏移量来自元素的中心 - 这是我在控制台中获得的警告。

and column width not getting reduced on UI. UI上的列宽不会减少。

Expected output:- I want to reduce the column width. 预期输出: - 我想减小列宽。

If this is HTML5 form - you cannot do that with Actions class as well as with Robot framework. 如果这是HTML5表单 - 您不能使用Actions类以及Robot框架。

You can try to make screenshot of web element and interact it with Sikuli library, eg: https://github.com/alexandrchumakin/Relay42ApiTest/blob/master/src/main/java/web/driver/WebDriverHelper.java#L35 您可以尝试制作Web元素的屏幕截图并与Sikuli库进行交互,例如: https//github.com/alexandrchumakin/Relay42ApiTest/blob/master/src/main/java/web/driver/WebDriverHelper.java#L35

Or you can implement JQuery that will do all this magic. 或者你可以实现将完成所有这些魔术的JQuery。

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

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