java 单选框_java工作复习——单选框

单选框:packagejkcs;importorg.openqa.selenium.By;importorg.openqa.selenium.WebDriver;importorg.openqa.selenium.firefox.FirefoxDriver;importorg.openqa.selenium.interactions.Actions;public classjdcs

{public static void main(String[] args) throwsInterruptedException

{

System.setProperty("webdriver.chrome.bin","?C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"); //设置安装路径,防止系统找不到

WebDriver driver= new FirefoxDriver(); //初始化FireFox浏览器实例,并打开浏览器

driver.manage().window().maximize();//最大化窗口

driver.get("https://www.baidu.com"); //打开一个网址,方法一

Thread.sleep(8000);

Actions action= newActions(driver);

action.moveToElement(driver.findElement(By.linkText("设置"))).perform(); //鼠标悬浮在 设置 元素上面

driver.findElement(By.className("setpref")).click(); //打开搜索设置

Thread.sleep(8000);boolean dy = driver.findElement(By.xpath("//*[@id='s1_1']")).isSelected();

System.out.println(dy);boolean dr = driver.findElement(By.xpath("//*[@id='s1_2']")).isSelected();

System.out.println(dr);

Thread.sleep(8000);

driver.findElement(By.xpath("//*[@id='s1_2']")).click();boolean drr = driver.findElement(By.xpath("//*[@id='s1_2']")).isSelected();

System.out.println(drr);

Thread.sleep(8000);

driver.quit();

}

}

执行结果:true

false

true

=================================================================================================================================单选框,容器01:packagejkcs;import java.util.*;importorg.openqa.selenium.By;importorg.openqa.selenium.WebDriver;importorg.openqa.selenium.WebElement;importorg.openqa.selenium.firefox.FirefoxDriver;importorg.openqa.selenium.interactions.Actions;public classjdcs

{public static void main(String[] args) throwsInterruptedException

{

System.setProperty("webdriver.chrome.bin","?C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"); //设置安装路径,防止系统找不到

WebDriver driver= new FirefoxDriver(); //初始化FireFox浏览器实例,并打开浏览器

driver.manage().window().maximize();//最大化窗口

driver.get("https://www.baidu.com"); //打开一个网址,方法一

Thread.sleep(8000);

Actions action= newActions(driver);

action.moveToElement(driver.findElement(By.linkText("设置"))).perform(); //鼠标悬浮在 设置 元素上面

driver.findElement(By.className("setpref")).click(); //打开搜索设置

Thread.sleep(8000);

List xss = driver.findElements(By.name("s1"));for( WebElement xs : xss )

{

System.out.println(xs.isSelected());

}

Thread.sleep(8000);

driver.quit();

}

}

执行结果:true

false

==================================================================================================================================单选框,容器02:packagejkcs;import java.util.*;importorg.openqa.selenium.By;importorg.openqa.selenium.WebDriver;importorg.openqa.selenium.WebElement;importorg.openqa.selenium.firefox.FirefoxDriver;importorg.openqa.selenium.interactions.Actions;public classjdcs

{public static void main(String[] args) throwsInterruptedException

{

System.setProperty("webdriver.chrome.bin","?C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"); //设置安装路径,防止系统找不到

WebDriver driver= new FirefoxDriver(); //初始化FireFox浏览器实例,并打开浏览器

driver.manage().window().maximize();//最大化窗口

driver.get("https://www.baidu.com"); //打开一个网址,方法一

Thread.sleep(8000);

Actions action= newActions(driver);

action.moveToElement(driver.findElement(By.linkText("设置"))).perform(); //鼠标悬浮在 设置 元素上面

driver.findElement(By.className("setpref")).click(); //打开搜索设置

Thread.sleep(8000);

List xss = driver.findElements(By.name("s1"));for( WebElement xs : xss )

{if ( xs.getAttribute("id").equals("s1_2") == true)

{if ( xs.isSelected() == false)

xs.click();

}

}

Thread.sleep(8000);

driver.quit();

}

}

相关资源:Leslie人口预测模型
表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
相关推荐
©️2020 CSDN 皮肤主题: 1024 设计师:白松林 返回首页