Advertisement
Guest User

Untitled

a guest
Jul 27th, 2016
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. import org.openqa.selenium.By;
  2. import org.openqa.selenium.SearchContext;
  3. import org.openqa.selenium.WebElement;
  4.  
  5. class ByTestId extends By {
  6.  
  7. private final String testId;
  8.  
  9. public ByPlaceholder(String testId) {
  10. this.testId = testId;
  11. }
  12.  
  13. @Override
  14. public List<WebElement> findElements(SearchContext context) {
  15. return context.findElements(By
  16. .xpath("//*[@testid = '"+testId+"']"));
  17. }
  18.  
  19. @Override
  20. public WebElement findElement(SearchContext context) {
  21. return context.findElement(By
  22. .xpath("//*[@testid = '"+testId+"']"));
  23. }
  24. }
  25.  
  26. //for single webelement
  27. WebElement el = driver.findElement(new ByTestId("addbutton"));
  28.  
  29. //for list of webelements
  30. WebElement el = driver.findElements(new ByTestId("addbutton"));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement