Trying to do a browserless solution as my cloud environment does not have Chrome/Firefox installed, but having issues with both of these drivers. Even headless Chrome/Firefox solutions still are looking for browser installations. I currently have had many different id/xpath combinations working for my automated testing but both PhantomJS and HTMLUnit cannot seem to find these elements. These elements I am trying to locate are in angular and seemed to make things a bit more difficult.
Here is the sample HTML I am trying to locate on the page:
<li ng-repeat="invoiceMenuItem in nav.invoiceMenu.menuItems" ng-class="{'active':invoiceMenuItem.selected}" id="invoiceMenuItem_4" style="" class="ng-scope ibm-active" role="presentation">
<a ng-click="nav.onSelectInvoiceMenuItem(invoiceMenuItem);$event.stopPropagation();" href="" class="ng-binding" role="tab" aria-selected="false" tabindex="-1" aria-label="Attachment Upload">Attachment Upload</a>
</li>
<a ng-click="nav.onSelectInvoiceMenuItem(invoiceMenuItem);$event.stopPropagation();" href="" class="ng-binding" role="tab" aria-selected="false" tabindex="-1" aria-label="Attachment Upload">Attachment Upload</a>
I have tried all of these which do work for Chrome/Firefox, but not PhantomJS/HTMLUnit:
driver.findElement(By.xpath("//li[@id='invoiceMenuItem_4']")).click();
driver.findElement(By.id("invoiceMenuItem_4")).click();
driver.findElement(By.xpath("/html[1]/body[1]/div[1]/div[1]/div[2]/div[1]/div[3]/div[2]/div[2]/ul[1]/li[9]")).click();
driver.findElement(By.xpath("//*[contains(text(), 'Attachment Upload')]")).click();
driver.findElement(By.xpath("//li[@ng-class='active':invoiceMenuItem.selected']")).click();
There is also this element here, which works for HTMLUnit, but not PhantomJS:
<li id="invoiceMenu" ng-show="nav.invoiceMenu.show" ng-class="{'active':nav.invoiceMenu.selected}" class="active" role="presentation">
<a ng-click="nav.onSelectInvoiceMenu();$event.stopPropagation();" role="tab" aria-selected="false" tabindex="-1" aria-label="Invoice">Invoice</a>
</li>
Here is one solution that was working, I have tried other similar combos to what I have used above and usually do not have problems with Chrome/Firefox drivers.
driver.findElement(By.xpath("//ul[@class='tabs']//li[@id='invoiceMenu']")).click();