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.pswp.cn/news/278042.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/278042.shtml
英文地址,請注明出處:http://en.pswp.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…