[JAVA #8] [Web Automation #8] Controlling STEEMIT web pages with Selenium #6 Window() [CN]

in #cn5 years ago

redsjavahouse1591357_1280.jpg
image source: pixabay


manage() 函数里有 window(), timeOuts(), cookie, ime() 管理函数。
今天就给大家介绍下最常用的window()。

image.png

函数描述
getPosition离画面左上角的浏览器位置
返回类型为 Point,它包含 getX(),getY(),moveBy(),move() 附加函数
getSize返回浏览器大小。是浏览器窗口的大小而不是浏览器内容大小。
返回类型是 Dimension, 它包含 getWidth(),getHeight() 等函数。
fullscreen设置浏览器全屏模式。同等于F11键。
maximize设置浏览器最大值。
setPosition设置浏览器的位置。
同于JS的 window.moveTo()。
setSize设置浏览器大小。同于 JS的 window.resizeTo()。

package com.steem.webatuo;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.Keys;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.WebDriverWait;

import io.github.bonigarcia.wdm.WebDriverManager;

public class Steemit {

    public static void main(String[] args) throws InterruptedException {
        WebDriverManager.chromedriver().setup();
        WebDriver driver = new ChromeDriver();
        driver.get("https://steemit.com");
        
        Point po = driver.manage().window().getPosition();
        Point newPo = new Point(po.getX() + 100, po.getY() + 200);
        driver.manage().window().setPosition(newPo);
        driver.manage().window().getPosition().move(po.getX(), po.getY());
        
        Dimension size = driver.manage().window().getSize();
        Dimension newSize = new Dimension(size.getWidth() + 500, size.getHeight() + 500);
        driver.manage().window().setSize(newSize);
        driver.manage().window().maximize();
        driver.manage().window().fullscreen();
        
        Wait<WebDriver> wait = new WebDriverWait(driver, 10);
        Thread.sleep(5000);
        driver.quit();
    }

}

.
.
.
.
[Cookie 😅]
Seleniun java lib version: 3.141.59

Sort:  

@tipu curate
来了😁

来自于 [WhereIn Android] (http://www.wherein.io)

帅哥/美女!请支持中文区的见证人, @abit @bobdos @ety001 @justyy @oflyhigh @partiko (首字母顺序),全投,一个都不要漏。感谢支持。

!thumbup
恭喜你!您的这篇文章入选 @justyy 今日 (2020-02-06) 榜单 【优秀的文章】, 回复本条评论24小时内领赏,点赞本评论将支持 @dailychina 并增加将来您的奖赏。
@justyy 是CN区的见证人,请支持他,给他投票,或者设置justyy为见证人代理。感谢!@justyy的主要贡献:https://steemyy.com

Congratulations! This post has been selected by @justyy as today's (2020-02-06) 【Good Posts】, Steem On! Reply to this message in 24 hours to get rewards. Upvote this comment to support the @dailychina and increase your future rewards! ^_^

SteemIt 工具、API接口、机器人和教程
SteemIt Tools, Bots, APIs and Tutorial



If you believe what I am doing, please consider a spare vote voting me here, thank you very much indeed.

@justyy - the author of https://SteemYY.com and I have been a Steem Witness for more than a year now.

Coin Marketplace

STEEM 0.16
TRX 0.13
JST 0.027
BTC 59466.22
ETH 2616.54
USDT 1.00
SBD 2.44