0

I'm working with Selenium Web Driver, with both Chrome and HTMLUnit. With Chrome, the following code works, but HTMLUnit returns an error saying that the element couldnt be found.

SeleniumUtils.goURL(driver, "https://someweb.com");
Thread.sleep(3000); //Added just in case it was loading time
List<WebElement> list = SeleniumUtils.getElements(driver, TrackingPage.getTableContent());

That last line will return null, with no elements found. The XPath used is :

return By.xpath("//*[@id=\"__xmlview1--idProductsTable-tblBody\"]/tr");

Works with Chrome, fails in XPath with HTMLUnit. Any idea?

The driver used is created like this:

HtmlUnitDriver driver = new HtmlUnitDriver();
Chema Lopez
  • 375
  • 2
  • 3
  • 9

2 Answers2

0

Try using this :

//*[@id='__xmlview1--idProductsTable-tblBody']/tr 

I have used single quotes here. It will no difference but you can give it a try and see if it works. Please do let me know if it works or not.

dangi13
  • 1,275
  • 1
  • 8
  • 11
0

Try this code :

List<WebElement> list = driver.findElements(By.xpath("//*[@id=\"__xmlview1--idProductsTable-tblBody\"]/tr"));
Hamza Torjmen
  • 250
  • 1
  • 2
  • 10
  • Thanks for answering. The 'SeleniumUtils.getElements' is exactly your code. I don't know how to format it in the comments, you can copy and paste and format it in your IDE. Sorry for the incovenience `public static List getElements(WebDriver driver, By element) { List result = null; try { result = driver.findElements(element); }catch(Exception e) { e.printStackTrace(); } return result; }` – Chema Lopez Jul 24 '18 at 11:28