Xpath query | Selenium Forum
M
Posted on 21/12/2015
public class WeBuy {

//private static final WebDriver IJavaScriptExecutor = null;

WebDriver driver=new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(25, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(25, TimeUnit.SECONDS);
driver.get("https://uk.webuy.com/search/index.php?stext=*&section=&catid=956");
List<WebElement>gameslinkpresentinsite=driver.findElements(By.xpath("//div[@class='searchRecord']/div[2]/h1/a"));
System.out.println("Total links present--->"+gameslinkpresentinsite.size());
List<WebElement>buttons= driver.findElements(By.xpath("//div[@class='searchBuyNowButton']"));
System.out.println("Total button present--->"+buttons.size());
System.out.println(buttons.get(1).getText());
System.out.println(buttons.get(0).getText());



Please explain in this code I used - Xpath for button List<WebElement>buttons= driver.findElements(By.xpath("//div[@class='searchBuyNowButton']"));


whats wrong in this xpath and why I m not getting any result for System.out.println(buttons.get(1).getText());??


If i use List<WebElement>buttons= driver.findElements(By.xpath("//div[@class='action']/div/a[2]")); I am getting correct result


Whats difference in these two xpath

M
Replied on 22/12/2015

it picking up hidden element

Responsive image

M
Replied on 22/12/2015

use this

List<WebElement> buttons = driver.findElements(By .xpath("//div[@class='searchBuyNowButton']/span[@class='listBuyButton_mx']"));