Advertisement
Guest User

Untitled

a guest
Jul 30th, 2014
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.48 KB | None | 0 0
  1. org.openqa.selenium.NoSuchElementException: Unable to find element with xpath == //table[@id='groupActions']/tbody/tr/td/button[@title='GDelYesButton']
  2.  
  3. driver.switchTo().alert();
  4.  
  5. <p:commandButton id="delete"
  6. action="MBeanPath"
  7. icon="ui-icon ui-icon-trash"
  8. value="Delete"
  9. title="GDeleteButton">
  10. <p:confirm header="Delete Record"
  11. message="Are you sure about deleting this record?"
  12. icon="ui-icon-alert"/>
  13. </p:commandButton>
  14.  
  15. <p:confirmDialog global="true" showEffect="fade">
  16. <p:commandButton title="GDelYesButton" value="Yes" styleClass="ui-confirmdialog-yes"/>
  17. <p:commandButton title="GDelNoButton" value="No" styleClass="ui-confirmdialog-no" />
  18. </p:confirmDialog>
  19.  
  20. package test.selenium;
  21.  
  22. import java.awt.Robot;
  23. import java.util.concurrent.TimeUnit;
  24. import java.util.concurrent.TimeoutException;
  25.  
  26. import org.openqa.selenium.Alert;
  27. import org.openqa.selenium.By;
  28. import org.openqa.selenium.WebDriver;
  29. import org.openqa.selenium.WebElement;
  30. import org.openqa.selenium.ie.InternetExplorerDriver;
  31. import org.openqa.selenium.support.ui.ExpectedCondition;
  32. import org.openqa.selenium.support.ui.Select;
  33. import org.openqa.selenium.support.ui.WebDriverWait;
  34. import org.testng.annotations.AfterTest;
  35. import org.testng.annotations.BeforeTest;
  36. import org.testng.annotations.Test;
  37.  
  38.  
  39. public class DeleteTestNG {
  40. WebDriver driver;
  41.  
  42. public Alert getCurrentAlert(){
  43. return driver.switchTo().alert();
  44. }
  45.  
  46. public DeleteTestNG() {
  47. }
  48.  
  49. /**
  50. * @throws java.lang.Exception
  51. */
  52. @BeforeTest
  53. public void setUp() throws Exception {
  54. // Use Internet Explorer and set driver;
  55. System.setProperty("webdriver.ie.driver","path");
  56. driver = new InternetExplorerDriver();
  57.  
  58. // And now use this to visit URL
  59. driver.get("pageURL");
  60. }
  61.  
  62. /**
  63. * @throws java.lang.Exception
  64. */
  65. @AfterTest
  66. public void tearDown() throws Exception {
  67. driver.close();
  68. }
  69.  
  70. @Test
  71. public final void test() {
  72. final WebElement formElement = driver.findElement(By.id("searchForm"));
  73. final Select drpHaulierelement = new Select(formElement.findElement(By.id("data_input")));
  74.  
  75.  
  76.  
  77. /*
  78. * List<WebElement> options = drpelement.getOptions(); for
  79. * (WebElement e : options) { System.out.println("Option " +
  80. * e.getText()); }
  81. */
  82. drpelement.selectByIndex(0);
  83.  
  84. // Now submit the form. WebDriver will find the form for us from the
  85. // element
  86. final WebElement submit = driver.findElement(By.id("Submit"));
  87. submit.click();
  88. try {
  89. Thread.sleep(3000);
  90. } catch (InterruptedException e) {
  91. System.out.println("Caught");
  92. }
  93.  
  94. // Test Search results
  95. final WebElement tableElement = driver.findElement(By.id("data_input_data"));
  96. System.out.println("Data Table child - " + tableElement.getText());
  97. final WebElement chkBoxElement1 = tableElement.findElement(By.xpath("//tbody[@id='data_input_data']/tr/td/div/div[2]"));
  98. System.out.println("chkBoxElement1 " + chkBoxElement1.getTagName()+ "--" + chkBoxElement1.getText());
  99. chkBoxElement1.click();
  100.  
  101. final WebElement chkBoxElement2 = tableElement.findElement(By.xpath("//tbody[@id='data_input_data']/tr[2]/td/div/div[2]"));
  102. System.out.println("chkBoxElement2 " + chkBoxElement2.getTagName()+ "--" + chkBoxElement2.getText());
  103. chkBoxElement2.click();
  104.  
  105. final WebElement gDeleteButton = tableElement.findElement(By.xpath("//table[@id='groupActions']/tbody/tr/td/button[@title='GDeleteButton']"));
  106. System.out.println("gDeleteButton " + gDeleteButton.getTagName() + "--"+ gDeleteButton.getText() + "--"+ gDeleteButton.getCssValue("title"));
  107. gDeleteButton.click();
  108.  
  109.  
  110. //driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  111. try {
  112. Thread.sleep(3000);
  113. } catch (InterruptedException e) {
  114. System.out.println("Caught");
  115. }
  116. //driver.switchTo().alert();
  117. //driver.switchTo().activeElement();
  118. //driver.switchTo().alert();
  119. final WebElement yesButtonElement = tableElement.findElement(By.xpath("//table[@id='groupActions']/tbody/tr/td/button[@title='GDelYesButton']"));
  120. System.out.println("yesButtonElement " + yesButtonElement.getTagName()+ "--" + yesButtonElement.getText());
  121. yesButtonElement.submit();
  122. }
  123.  
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement