Greetings! Currently, I am exploring the integration of selenium webdriver with mocha and node js in order to automate testing for a Single Page Application (SPA). My objective is simple - to locate a specific tab and perform a click action on it. The HTML content has been successfully loaded into the test environment. Below is a snippet of the code:
<div id="Tabs">
<ul>
<li> <span> one </span></li>
<li> <span> two </span></li>
...
<li> <span> six </span></li>
</ul>
</div>
Within my test.js file, the script is architected as follows:
describe("MYHtml",function(){
var driver;
var tabs;
driver = new webdriver.Builder()
.forBrowser('firefox')
.build();
driver.get("file:///home/myhtml.html");
test.after(function() {
driver.quit();
});
before(function(done){
driver.findElement(By.id("Tabs")).then(function(e){
e.findElements(By.tagName("li")).then(function(b){
console.log("before got tabs length " + b.length);
tabs=b;
done();
});
});
});
test.it("we have some tabs",function(done){
assert.strictEqual(tabs.length,6);
console.log("we have tabs " + tabs.length);
done();
});
test.it("can find a tab name",function(done){
var span;
for(var i=0;i<tabs.length;i++){
tabs[i].findElements(By.tagName("span"))
.then(function(span){
console.log("Field??" + span.getText());
//return span;
done();
});
}
}); )};
While the test case "we have some tabs" passes without issues, the "can find a tab name" test case encounters an error as shown below:
1 failing
1) MYHtml can find tab name: TypeError: span.getText is not a function
The aim here is to search for a li element corresponding to the span text value of '2' so that a subsequent click operation can be executed.