As per the below code, I navigate to a specified URL and select the values in the from and to field.
The xpaths mentioned in the 3rd and 4th line, each returns 2 instances.
In the third line, findElement selected the first instance.
But in the fourth line, the findElement method selected the second instance.
As per my understanding, findElement method will always select the first instance.
So, is there any specific xpath logic which caused it to select the second instance or what is the difference between 4th and 5th line in this context ?
Below is the code:
driver.get(“https://www.spicejet.com”);
driver.findElement(By.xpath(“//input[@id=’ctl00_mainContent_ddl_originStation1_CTXT’]”)).click();
driver.findElement(By.xpath(“//a[@value=’GOI’]”)).click();
driver.findElement(By.xpath(“//a[@value=’DEL’]”)).click();
driver.findElement(By.xpath(“(//a[@value=’DEL’])[2]”)).click();
Appreciate your help on this.
Source: Read More