Webdriver利用JS给只读属性的文本框赋值
来源:互联网 发布:windows10自带优化 编辑:程序博客网 时间:2024/05/13 12:49
给只读文本框赋值,这里列举了两种方式。一种是去掉文本框的只读属性,另一种是添加value属性,直接赋值。
只读文本框截图
package com.test;import org.openqa.selenium.By;import org.openqa.selenium.JavascriptExecutor;import org.openqa.selenium.WebDriver;import org.openqa.selenium.chrome.ChromeDriver;import org.testng.annotations.AfterTest;import org.testng.annotations.BeforeTest;import org.testng.annotations.Test;public class ReadOnly {WebDriver driver = null;@BeforeTestpublic void beforeTest() {System.setProperty("webdriver.chrome.driver", "./plugin/driver/chromedriver.exe");driver = new ChromeDriver();}@Testpublic void readonly_input() throws InterruptedException {driver.get("file:///D:/location/locator.html");//方法一/*String remove_readonly_js = "$('#readonly').removeAttr('readonly')";if(driver instanceof JavascriptExecutor){((JavascriptExecutor)driver).executeScript(remove_readonly_js);}driver.findElement(By.id("readonly")).sendKeys("Bingo");*///方法二/*JavascriptExecutor js = null;if(driver instanceof JavascriptExecutor){js = (JavascriptExecutor)driver;}js.executeScript("$('#readonly').removeAttr('readonly')");driver.findElement(By.id("readonly")).sendKeys("Method 2");*///方法三String set_value_readonly_js = "$('#readonly').attr('value', 'Method3')";if(driver instanceof JavascriptExecutor){((JavascriptExecutor)driver).executeScript(set_value_readonly_js);}Thread.sleep(5000);}@AfterTestpublic void afterTest() {if(driver != null)driver.close();}}
0 0
- Webdriver利用JS给只读属性的文本框赋值
- C# 可以利用反射给只读属性赋值吗?
- 只读属性的赋值
- 用js给属性为readonly的文本框赋值 无效的解决方法
- 利用“反射”给类的属性赋值。
- js怎么自动给文本框赋值
- PHP实现设置文本框的只读属性
- input 文本框密码框的只读属性
- 【jQuery】用jQuery给文本框添加只读属性【readOnly】
- 【jQuery】用jQuery给文本框添加只读属性【readOnly】
- JS给文本框赋值后,在页面后台取不到文本框值的解决方法
- Js给文本框赋值后,禁止再输入文本框的方法汇总
- JS给对象属性赋值
- 文本框只读属性
- 利用反射给对象的属性赋值的例子
- 014--利用模型的didSet属性给UI赋值
- js控制文本框只读
- webdriver中利用js来向富文本框书写内容
- android ListView详解
- POJ 2653 Pick-up sticks
- Leetcode: Longest Consecutive Sequence 理解分析
- eclipse创建maven项目
- spring与mybatis三种整合方法
- Webdriver利用JS给只读属性的文本框赋值
- tomcate 安装服务
- CSS Border & Padding & Margin
- 拦截器 介绍
- 实现TIME类的运算符重载
- /proc 这个目录是虚拟在内存中的,不在硬盘保存,
- 第十一届浙江省赛题目
- jQuery.data()和HTML5之data-属性
- jquery 拒绝访问 无法加载 跨域问题