Guest User

Untitled

a guest
Jun 18th, 2018
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. selenium.check("//input[@name=’checkboxes[]’ and @value=’cb3’]");
  2.  
  3. isChecked = driver.findElement(By.xpath("//input[@type='checkbox']"));
  4.  
  5. if (isChecked = false) {
  6. check the box;
  7. } else {
  8. do nothing;
  9. }
  10.  
  11. WebElement checkBox1;
  12. WebElement checkBox3;
  13.  
  14. checkBox1 = driver.findElement(By.cssSelector("input[value='cb1']"));
  15. checkBox3 = driver.findElement(By.cssSelector("input[value='cb3']"));
  16.  
  17. if(!checkBox1.isSelected()){
  18. checkBox1.click();
  19. }
  20.  
  21. //checkBox3 is selected by default
  22. if(checkBox3.isSelected()){
  23. checkBox3.click();
  24. }
  25.  
  26. List<WebElement> selectElements=
  27. driver.findElements(By.cssSelector("input[name='checkboxes[]']"));
  28.  
  29. selectElements.get(0).click();
  30.  
  31. if( selectElements.get(2).isSelected()){
  32. selectElements.get(2).click();
  33. }
  34.  
  35. for(WebElement checkbox : selectElements){
  36. // uncheck 'em all
  37. if(checkbox.isSelected()){
  38. checkbox.click();
  39. }
  40. }
  41.  
  42. IWebElement element = driver.findElement(By.xpath("//input[@type='checkbox']"));
  43. if (!element.Selected)
  44. {
  45. element.Click();
  46. }
  47.  
  48. IWebElement chkBox = driver.FindElement(By.Id("some id "));
  49. if (chkBox.Selected) {
  50. //perform actions
  51. } else {
  52. //perform actions
  53. }
  54.  
  55. /* load that webelement list of radio buttons. then follow the below code & logic */
  56. List<WebElement> rdBtn_Sex = driver.findElements(By.name("sex"));
  57.  
  58. // Create a boolean variable which will hold the value (True/False)
  59. boolean bValue = false;
  60.  
  61. // This statement will return True, in case of first Radio button is selected
  62. bValue = rdBtn_Sex.get(0).isSelected();
  63.  
  64. // This will check that if the bValue is True means if the first radio button is selected
  65. if (bValue = true) {
  66. // This will select Second radio button, if the first radio button is selected by default
  67. rdBtn_Sex.get(1).click();
  68. } else {
  69. // If the first radio button is not selected by default, the first will be selected
  70. rdBtn_Sex.get(0)).click();
  71. }
Add Comment
Please, Sign In to add comment