Selenium-基础操作

一、测试代码

@Test

public void test() {

WebDriver driver = new FirefoxDriver();

 

// 打开当前包中的index页面

driver.get("file:///D:/%E8%B5%B5%E6%AC%A2/Selenium/Selenium/src/com/html/index.html");

WaitSeconds(1000);

// 清除用户输入

driver.findElement(By.id("fname")).clear();

WaitSeconds(1000);

// 输入

driver.findElement(By.id("fname")).sendKeys("这是输入的内容");

WaitSeconds(1000);

// 获取元素内容

String text = driver.findElement(By.name("jsh")).getText();// 这种方法是获取元素的文本值

System.out.println("获取元素内容" + text);

WaitSeconds(1000);

// 以下这种方式是获取input的value值

text = driver.findElement(By.id("fname")).getAttribute("value");

System.out.println("value获取元素内容" + text);

WaitSeconds(1000);

// 单击操作

driver.findElement(By.id("idOfButton")).click();

WaitSeconds(1000);

// 通过浏览器记录向后导航

driver.findElement(By.linkText("This is a link")).click();

driver.navigate().back();

WaitSeconds(1000);

// 向前导航

driver.navigate().forward();

// 刷新

driver.navigate().refresh();

// 关闭网页当前页面

driver.close();

// 关闭浏览器,如果有其他选项卡一并关闭

driver.quit();

// 在windows间移动

WaitSeconds(3000);

driver.switchTo().window("MsgWindow");

// 拖拽,首先拖拽的对象要实现拖拽的方法

WaitSeconds(3000);

WebElement source=driver.findElement(By.id("sourceImage"));

WebElement target=driver.findElement(By.id("targetDiv"));

Actions actions=new Actions(driver);

actions.dragAndDrop(source, target).build().perform();

//actions.clickAndHold(source).moveToElement(target).perform();

// 通过标签

driver.findElement(By.tagName("input")).sendKeys("aaaaa");

// 通过linktext

driver.findElement(By.linkText("This is a link")).click();

driver.findElement(By.partialLinkText("This is")).click();

// 处理下拉列表,找到元素之后new一个select对象

WebElement dElement=driver.findElement(By.id("testingDropdown"));

Select dropdownlist=new Select(dElement);

dropdownlist.selectByIndex(3);

WaitSeconds(2000);

dropdownlist.selectByValue("Performance");

WaitSeconds(2000);

dropdownlist.selectByVisibleText("Manual Testing");

WaitSeconds(2000);

dropdownlist.deselectByIndex(2);

// Alert

driver.findElement(By.id("Alert")).click();

WaitSeconds(2000);

driver.switchTo().alert().accept();

WaitSeconds(2000);

driver.findElement(By.id("Confirm")).click();

WaitSeconds(2000);

String txt=driver.switchTo().alert().getText();

System.out.println(txt);

WaitSeconds(2000);

driver.switchTo().alert().dismiss();

// 滚动,需要调用js方法scrollBy(x,y)

JavascriptExecutor javascriptExecutor=(JavascriptExecutor)driver;

javascriptExecutor.executeScript("scrollBy(0,4000)");

}

二、以上测试代码针对的html页面

 

<html>

<head>

<title>简单测试页面</title>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="stylesheet" href="src/com/html/bootstrap.min.css">

<script src="src/com/html/jquery-3.3.1.min.js"></script>

<script src="src/com/html/bootstrap.min.js"></script>

<style></style>

</head>

<body style="font-family: cursive;">

<div class="container">

<div class="row">

<div class="col-md-offset-2 col-md-8" style="font-size: 30; margin-top: 40px; ">

用于自动化测试的Web页面示例

</div>

</div>

 

<div class="row">

<div class="col-md-12" style="font-size:20px; margin-top:40px;" name="jsh">

This is sample webpage with dummy elements that will help you in learning selenium automation.

</div>

</div>

<br>

<div class="row">

<div class="col-md-12" style="font-size:15px;">

<b>This is sample text.</b>

</div>

</div>

<br>

 

<div class="row">

<div class="col-md-12" style="font-size:15px;">

<p> <b>Link : </b><a href="https://www.yiibai.com/">This is a link</a></p>

</div>

</div>

<br>

 

<div class="row">

<div class="col-md-12" style="font-size:15px;">

<p><b>TextBox : </b><input id="fname" type="text" name="firstName" value="文本框内容" ><input id="fname2" type="text" name="firstName" value="第二个文本框" ></p>

</div>

</div>

<br>

 

<div class="row">

<div class="col-md-12" style="font-size:15px;">

<p><b>Button : </b><button id="idOfButton" title="Click me!!" type="button" οnclick="this.style.background='green';">Submit</button></p>

</div>

</div>

<br>

 

<div class="row">

<div class="col-md-12" style="font-size:15px;">

<p><b>Radio button : </b>

<form action="#">

<input id="male" type="radio" name="gender" value="male"> Male

<input id="female" type="radio" name="gender" value="female"> Female

</form>

</p>

</div>

</div>

<br>

 

<div class="row">

<div class="col-md-12" style="font-size:15px;">

<p><b>Checkbox :</b>

<form action="#">

<input type="checkbox" class="Automation" value="Automation"> Automation Testing

<input type="checkbox" class="Performance" value="Performance"> Performance Testing

</form>

</p>

</div>

</div>

<br>

 

<div class="row">

<div class="col-md-12" style="font-size:15px;">

<p><b>Drop down :</b>

<select id="testingDropdown">

<option id="automation" value="Automation">Automation Testing</option>

<option id="performance" value="Performance">Performance Testing</option>

<option id="manual" value="Manual">Manual Testing</option>

<option id="database" value="Database">Database Testing</option>

</select>

</p>

</div>

</div>

<br>

 

<div class="row">

<div class="col-md-12" style="font-size:15px;">

<p><button id="dblClkBtn" οndblclick="alert('hi, Yiibai Testing');">Double-click to generate alert box</button></p>

</div>

</div>

<br>

 

<div class="row">

<div class="col-md-12" style="font-size:15px;">

<p><b>Click button to generate Alert box : </b>

<button id="Alert" οnclick="alert('hi, Yiibai Testing');">Generate Alert Box</button>

</p>

</div>

</div>

<br>

 

<div class="row">

<div class="col-md-12" style="font-size:15px;">

<p> <b> Click button to generate Confirm box : </b>

<button id="confirm" οnclick="generateConfirmBox()">Generate Confirm Box</button>

</p>

<p id="demo"></p>

</div>

</div>

<br>

 

<div class="row">

<div class="col-md-12" style="font-size:15px;">

<p>Drag and drop example- drag the below image on the textbox</p>

 

<div id="targetDiv" οndrοp="drop(event)" οndragοver="allowDrop(event)" style="width:400px;height:150px;padding:10px;border:1px solid #aaaaaa;"></div>

<img id="sourceImage" src="https://www.yiibai.com/static/img/logo.png" alt="yiibai" draggable="true" οndragstart="drag(event)" height="120px">

 

</div>

</div>

<br>

</div>

<script>

//window.open('http://www.baidu.com','MsgWindow');

function generateConfirmBox()

{

var x;

var r=confirm("Press a button!");

if (r==true)

{

x="You pressed OK!";

}

else

{

x="You pressed Cancel!";

}

document.getElementById("demo").innerHTML=x;

}

 

function allowDrop(ev)

{

ev.preventDefault();

}

 

function drag(ev)

{

ev.dataTransfer.setData("Text",ev.target.id);

}

 

function drop(ev)

{

ev.preventDefault();

var data=ev.dataTransfer.getData("Text");

ev.target.appendChild(document.getElementById(data));

}

 

</script>

</body>

</html>

 

转载于:https://www.cnblogs.com/zh1990/p/10648969.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/278042.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

开发针对特殊租户的Teams机器人

有些朋友问到&#xff0c;如果想要开发一个bot针对于Teams的某些租户&#xff0c;如何做&#xff1f;实际上微软的Teams的SDK早就提供了类似的功能。 如果你使用的是Javascript/Node.JS开发&#xff0c;使用session.message.sourceEvent.tenant.id 就可以知道当前消息来自于哪…

行业看点 | 英特尔成功开发超导量子计算芯片 推动产业加速发展

量子计算将会成为下一次技术革命的核心&#xff0c;你可能认为它还很遥远&#xff0c;实际上量子计算会比预料的来得早。近期&#xff0c;英特尔在量子芯片方面取得突破&#xff0c;让量子计算朝着现实前进了一大步。 继IBM公司发布了自主量子处理器&#xff0c;谷歌着手研究基…

Teams App抽奖机器人 - 基础架构

今天我们来聊一下&#xff0c;一个Teams app的infrastructure&#xff0c;我在考虑LuckyDraw的主要出于这么几个出发点&#xff1a; 可管理性。因为这是一个个人产品&#xff0c;以后维护工作也只有我一个人&#xff0c;所以我希望整个infrastructure简单、易管理&#xff0c;不…

Teams Bot的ServiceLevel测试

每一个Teams bot实际上就是一个web api服务&#xff0c;这个服务通过Bot Framework和Teams进行通讯&#xff0c;所以对于Teams app的测试就是对于一个api service的测试。 软件行业发展到如今&#xff0c;测试技术已经趋于成熟。单元测试&#xff0c;冒烟测试&#xff0c;整合…

BZOJ1016:[JSOI2008]最小生成树计数——题解

https://www.lydsy.com/JudgeOnline/problem.php?id1016 现在给出了一个简单无向加权图。你不满足于求出这个图的最小生成树&#xff0c;而希望知道这个图中有多少个不同的最小生成树。&#xff08;如果两颗最小生成树中至少有一条边不同&#xff0c;则这两个最小生成树就是不…

如何做Teams Bot的测试覆盖

在我昨天的文章中介绍了如果对Teams bot做service level的测试&#xff0c;那到底要写多少的测试代码才算够&#xff1f;如何才算测试到位了&#xff1f;这个时候我们就需要用”测试覆盖率”来衡量&#xff0c;虽然覆盖率高并不一定代表着就可以高枕无忧的以为我们软件质量高了…

Spring Boot开发MongoDB应用实践

本文继续上一篇定时任务中提到的邮件服务&#xff0c;简单讲解Spring Boot中如何使用MongoDB进行应用开发。 上文中提到的这个简易邮件系统大致设计思路如下&#xff1a; 1、发送邮件支持同步和异步发送两种 2、邮件使用MongDB进行持久化保存 3、异步发送&#xff0c;直接将邮件…

Teams Bot如何做全球化

Office365在全球有大量的用户&#xff0c;可以说是拥有最多用户的商业SaaS平台。Teams最近在发展迅猛&#xff0c;有1300万日活用户&#xff0c;已经超越了Slack。? Microsoft Teams overtakes Slack with 13 million daily users 我在设计Teams LuckyDraw bot的时候就希望我…

QuickBI助你成为分析师-邮件定时推送

创建报表过程中经常需要将报表情况定时推送给其他用户&#xff0c;及时了解数据情况。高级版本邮件推送功能支持仪表板周期性推送到订阅人&#xff0c;默认以当前登录者视角查看&#xff0c;同时支持结合 行级权限进行权限控制 和 结合全局参数功能确定邮件推送内容参数&#x…

2019年5月 Teams Community Call (China)

这个月有四个话题&#xff1a; Tony Xia&#xff1a;这个月的Teams的产品更新&#xff0c;Teams开发能力的更新&#xff0c;开源项目更新&#xff0c;库更新王远&#xff1a;升级/迁移到Microsoft Teams刘钰&#xff1a;Teams账号注册探索指南Paul Zhang/Cheung&#xff1a;Bu…

修改oracle 管理员密码 cmd

1.sqlplus/nolog 2.conn / as sysdba 3.alter user 用户名 identified by 新密码;转载于:https://www.cnblogs.com/taoqidexiaomao/p/9006927.html

在2019年6月Teams Community Call上分享的Teams app基础架构视频

我在2019年6月Teams Community Call(China)上分享的如何在azure上搭建典型的teams bot的基础架构 会议视频&#xff1a; 15:00 - 33:00 Download Video

解决 spring-cloud-starter-zipkin 启动错误

应用场景&#xff1a;Spring Boot 服务添加 Zipkin 依赖&#xff0c;进行服务调用的数据采集&#xff0c;然后进行 Zipkin-Server 服务调用追踪显示。 示例pom.xml配置&#xff1a; <parent><groupId>org.springframework.boot</groupId><artifactId>s…

什么是Microsoft Teams的App Studio

Teams的app studio很多用户可能不知道&#xff0c;但是对于一个teams平台的开发人员来说&#xff0c;这个是开发利器&#xff0c;利用这个工具你可以轻松的配置manifest文件&#xff0c;可以轻松的一站式创建teams app所需要的所有东西。而且你可以很方便的可视化配置adaptive …

Spring Cloud-鸿鹄Cloud分布式微服务云系统—架构图

这边结合了当前大部分企业的通用需求&#xff0c;包括技术的选型比较严格、苛刻&#xff0c;不仅要用业界最流行的技术&#xff0c;还要和国际接轨&#xff0c;在未来的5~10年内不能out。作为公司的架构师&#xff0c;也要有一种放眼世界的眼光&#xff0c;不仅要给公司做好的技…

Teams bot的调用限制

上个月Teams团队发布了对Teams app/bot调用api的频率的限制。这也从侧面说明Teams app越来越多&#xff0c;Teams团队需要优先保证Teams本身的计算资源&#xff0c;来提供流畅的用户体验。 具体的每个限制指标在这里&#xff1a; https://docs.microsoft.com/en-us/microsoftt…

Array的sort方法

作为一个刚开始学习的前端&#xff0c;小结一下&#xff1a;sort方法&#xff1a; 如果调用该方法时没有使用参数&#xff0c;将按字母顺序对数组中的元素进行排序&#xff0c;说得更精确点&#xff0c;是按照字符编码的顺序进行排序。要实现这一点&#xff0c;首先应把数组的元…

如何使用ARM创建Teams Bot所需要的Azure资源

相信很多devops已经全面开始使用ARM来创建azure资源了&#xff0c;ARM有很多方便的地方&#xff0c;比如简单易学&#xff0c;Infrastructure as Code&#xff0c;但是深入使用ARM开始会发现一些有待改进的方面。这篇文章主要是分享一下我在做Teams app的时候使用ARM来创建资源…

Bot Service自带的数据分析统计功能

每个产品上线后都希望自己能实时看到多少用户在使用我的产品&#xff0c;我的服务&#xff0c;有多少使用量&#xff0c;有没有遇到问题。市面上做用户数据、行为分析的公司也不少&#xff0c;但是大多数都需要我们修改一些代码来集成第三方的sdk库。 我的teams app上线后也急…

LuckyDraw bot有幸被提名为微软2019的People's Choice app

上个月微软进行了一个全世界提名活动&#xff0c;目标是选出微软2019年度People’s Choice app。 很幸运&#xff0c;我的LuckyDraw bot得到了来自世界各地使用者的投票&#xff0c;其中也包含Teams中国社区和很多朋友的支持。 https://developer.microsoft.com/en-us/microso…