I'm using selenium 3.4.0 and trying to click an element on a page. I just used Thread.sleep(12000) (which is max wait) before I perform click action but still it throws nosuchelement exception. I used other browsers like chomre --headless but it works pretty perfect and similarly it works fine with firefox and chorme UI browsers as well.
Code:
WebDriver iDriver=new HtmlUnitDriver();
iDriver.get("https://www.xyz:8080/#!/test/createTest");
String title = iDriver.getTitle();
System.out.println(title);
iDriver.manage().window().setSize(new Dimension(1920, 1200));
Thread.sleep(13000);
org.testng.Assert.assertEquals("UI", title);
JavascriptExecutor executor = (JavascriptExecutor)iDriver;
executor.executeScript("arguments[0].click();", iDriver.findElement(By.xpath(".//span[@class='path']//a[contains(@href,'/testresource/createTestRequest')]")));
Tried with Javascriptexecutor.click() as above as well normal click() method but both didn't work.
The same above script executing perfectly fine with other browsers.
Exception:
org.openqa.selenium.NoSuchElementException: Unable to locate a node using //span[@class='path']//a[contains(@href,'/testresource/createTestRequest')]
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'L-MAA-25006133', ip: '10.229.101.11', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_191'
Driver info: driver.version: HtmlUnitDriver
Ideally I just want to execute the above script in linux box which is in Google Cloud Platform. And I dont have permission to install any browser like (chrome, firefox binaries) over there to execute the scripts against such browsers. Tried chrome --headless option but It still looking Chrome binary (/usr/bin/chrome-browser) in physical path to set in chromeoptions. We can't do that on that machine. So, I just written script where I no need to specify any browser binary and it will execute as headless browser without support of chrome or firefox binaries.
Please give me you thoughts about this. If there is any better way to do this I will try to do in that way as well.