Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. driver.findElement(By.xpath("//input[@accesskey='9']"));
  2.  
  3. td style="width: 5%;">
  4. <input type="checkbox" data-bind="attr: { accesskey: Id }" accesskey="6">
  5. </td>
  6. <td style="width: 5%;">
  7. <input type="checkbox" data-bind="attr: { accesskey: Id }" accesskey="7">
  8. </td>
  9.  
  10. public void portfolioRenewalSearch(String portfolioId) throws Exception {
  11.  
  12. try {
  13. driver.findElement(By.xpath("//input[@accesskey= portfolioId]"))
  14. .click();
  15. } catch (AssertionError Ae) {
  16. Ae.printStackTrace();
  17. }
  18. }
  19.  
  20. public void portfolioRenewalSearch(String portfolioId) throws Exception {
  21. try {
  22. driver.findElement(By.xpath("//input[@accesskey="+portfolioId+"]"))
  23. .click();
  24. } catch (AssertionError Ae) {
  25. Ae.printStackTrace();
  26. }
  27. }
  28.  
  29. Here is the solution for index variable
  30.  
  31. Let's say, you have found 5 elements with same locator and you would like to perform action on each element by providing index number (Here, variable is used for index as "i")
  32.  
  33. for(int i=1; i<=5; i++)
  34. {
  35. string xPathWithVariable = "(//div[@class='className'])" + "[" + i + "]";
  36. driver.FindElement(By.XPath(xPathWithVariable)).Click();
  37. }
  38.  
  39. It takes XPath as below
  40. (//div[@class='className'])[1]
  41. (//div[@class='className'])[2]
  42. (//div[@class='className'])[3]
  43. (//div[@class='className'])[4]
  44. (//div[@class='className'])[5]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement