免费预览已结束,剩余1页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
package .selenium;import java.util.concurrent.TimeUnit;import org.junit.*;import static org.junit.Assert.*;import org.openqa.selenium.*;import org.openqa.selenium.chrome.ChromeDriver;public class First private WebDriver driver; private String baseUrl; private boolean acceptNextAlert = true; private StringBuffer verificationErrors = new StringBuffer(); Before public void setUp() throws Exception System.setProperty(webdriver.chrome.driver,D:/chromedriver_win32/chromedriver.exe); driver = new ChromeDriver(); baseUrl = /; driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); Test public void testFirst() throws Exception driver.get(baseUrl + /); driver.findElement(By.id(kw).click(); driver.findElement(By.id(kw).clear(); driver.findElement(By.id(kw).sendKeys(天气预报); driver.findElement(By.id(su).click(); driver.findElement(By.xpath(/tableid=1/tbody/tr/td/h3/a/em2).click(); After public void tearDown() throws Exception driver.quit(); String verificationErrorString = verificationErrors.toString(); if (!.equals(verificationErrorString) fail(verificationErrorString); private boolean isElementPresent(By by) try driver.findElement(by); return true; catch (NoSuchElementException e) return false; private boolean isAlertPresent() try driver.switchTo().alert(); return true; catch (NoAlertPresentException e) return false; private String closeAlertAndGetItsText() try Alert alert = driver.switchTo().alert(); String alertText = alert.getText(); if (acceptNextAlert) alert.accept(); else alert.dismiss(); return alertText; finally acceptNextAlert = true; # -*- coding: UTF-8 -*-from selenium import webdriverfrom mon.by import Byfrom mon.keys import Keysfrom selenium.webdriver.support.ui import Selectfrom mon.exceptions import NoSuchElementExceptionimport unittest, time, reimport osclass Pythontest(unittest.TestCase): def setUp(self): chromedriver = D:chromedriver_win32chromedriver.exe os.environwebdriver.chrome.driver = chromedriver self.driver = webdriver.Chrome(chromedriver) self.driver.implicitly_wait(30)#智能等待30秒 self.base_url = self.verificationErrors = self.accept_next_alert = True def test_python(self): driver = self.driver driver.get(self.base_url + /)# driver.find_element_by_name(wd).click()# print(1)# driver.find_element_by_name(wd).clear()# print(2) driver.find_element_by_name(wd).send_keys(uselenuim) print(3) driver.find_element_by_id(su).click() print(4) driver.find_element_by_link_text(朋友网).click() def is_element_present(self, how, what): try: self.driver.find_element(by=how, value=what) except NoSuchElementException, e: return False return True def is_alert_present(self): try: self.driver.switch_to_alert() except NoAlertPresentException, e: return False return True def close_alert_and_get_its_text(self): try: alert = self.driver.switch_to_alert() alert_text = alert.text if self.accept_next_alert: alert.accept() else: alert.dismiss() return alert_text finally: self.accept_next_alert = True def tearDown(self): self.driver.quit() self.assertEqual(, self.verificationErrors)if _name_ = _main_: unittest.main()package .selenium;import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.openqa.selenium.WebElement;import org.openqa.selenium.chrome.ChromeDriver;import org.openqa.selenium.support.ui.ExpectedCondition;import org.openqa.selenium.support.ui.WebDriverWait;public class Selenium2Example public static void main(String args) /创建一个WebDriver实例 System.setProperty(webdriver.chrome.driver,D:/chromedriver_win32/chromedriver.exe); WebDriver driver= new ChromeDriver(); / 访问google driver.get(); / 另一种访问方法 / driver.navigate().to(); / 找到文本框 WebElement element= driver.findElement(B(wd); / 输入搜索关键字 element.sendKeys(Selenium); /提交表单 WebDriver会自动从表单中查找提交按钮并提交 element.submit(); / 检查页面title System.out.println(Page title is: + driver.getTitle(); / google查询结果是通过javascript动态呈现的. / 设置页面等待10秒超时 (new WebDriverWait(driver, 10).un
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 专题09 连词并列句复合句(课件)-2024年中考英语二轮复习讲练测
- 2024年广东省中考历史二轮复习+:+专题四++近代中国的救亡图存与近代化++课件
- 水氧治疗仪的优势
- 规范办学情况汇报
- 帅康净水器导购员手册教材
- 教学查房正文
- 生态系统的能量流动 终极
- 教学护理查房4
- 撕脱伤护理查房
- 护理高胆红素血症查房
- 牛奶生产线流程图
- 图书馆管理系统——软件工程导论
- 氢氟酸硝酸使用操作规程
- 血氧仪项目可行性研究报告写作范文
- 人教版PEP三年级英语下册电子作业本
- 电动给水泵施工方案
- 空压机故障跳机应急演练方案
- 报价单模板word
- 变电工程综合单价表(安装部分)
- 残疾人精准康复工作自查报告
- Sentaurus在ESD防护器件设计中的应用PPT课件
评论
0/150
提交评论