栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Selenium Web驱动程序:findElement(By.name…和无头浏览器

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Selenium Web驱动程序:findElement(By.name…和无头浏览器

我已经解决了....我在组织中的代理后面,所以我必须设置代理。

我发现了这一点:HtmlUnitDriver似乎没有正在加载page。

寻找FunThomas424242评论,并观看此链接https://selenium.googlepre.com/git/docs/api/java/org/openqa/selenium/htmlunit/HtmlUnitDriver.html

因此,正确的代码如下:

package headlessBrowser;import org.openqa.selenium.By;import org.openqa.selenium.WebElement;import org.openqa.selenium.htmlunit.HtmlUnitDriver;public class TestOne {public static void main(String[] args) {    // Declaring and initialising the HtmlUnitWebDriver    HtmlUnitDriver unitDriver = new HtmlUnitDriver();    // Necessary set Proxy if you're behind it !!!!     unitDriver.setProxy("proxy.YOUR-ORGANIZATION.COM", XXXX);    // open google.com webpage    unitDriver.get("http://www.google.com");    System.out.println("Title of the page is -> " + unitDriver.getTitle());    // find the search edit box on the google page    WebElement searchBox = unitDriver.findElement(By.name("q"));    // type in Selenium    searchBox.sendKeys("Selenium");    // find the search button    WebElement button = unitDriver.findElement(By.name("btnG"));    // Click the button    button.click();    System.out.println("Title of the page is -> " + unitDriver.getTitle());   }}

“核心”行如下

    // Necessary set Proxy if you're behind it !!!!     unitDriver.setProxy("proxy.YOUR-ORGANIZATION.COM", XXXX);

您必须在其中更新代理配置的位置。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/425906.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号