Asserting BBC Top menu item count | Selenium Forum
S
Shilpa Posted on 09/05/2019

How can I assert BBC Top menu count using feature files?


A
Ashish Thakur Replied on 09/05/2019

Then top menu should have

|Item 1||Item 2||Item 3||Item 4|


S
Shilpa Replied on 10/05/2019

I have got following code for clicking on hidden elements in menu:

public static boolean setMenuItem(String itemName){
WebElement topMenuItem = driver.findElement(By.id(TOPMENU));
List<WebElement> topMenu = topMenuItem.findElements(By.tagName("a"));
WebElement more = topMenuItem.findElement(By.xpath("//*[@id=\"orb-nav-more\"]/a"));
more.click();
int count =1;
boolean result = false;

String part1 = "//*[@id=\'orb-panel-more\']/div/ul/li[";
String part2 = "]/a";
for (WebElement e1:topMenu){

if(e1.isDisplayed() ){
if(e1.getText().equalsIgnoreCase(itemName)){
softAssert.assertThat(true);
result = true;
break;
}else{
softAssert.assertThat(false);
result = false;
}
}else{
Actions build = new Actions(driver);
build.moveToElement(e1).build().perform();
WebElement m2m= e1.findElement(By.xpath(part1+count+part2));
if(m2m.getText().equalsIgnoreCase(itemName)){
softAssert.assertThat(true);
result = true;
break;
}else{
softAssert.assertThat(false);
result = false;
}

}
count++;

}
return result;

}


This code works fine when executed in Chrome. However, when I run it in Firefox using Gecko driver, I am getting following error:

at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at org.openqa.selenium.remote.RemoteWebDriver.perform(RemoteWebDriver.java:618)
at org.openqa.selenium.interactions.Actions$BuiltAction.perform(Actions.java:639)
at pageobjects.BbcLandingPage.setMenuItem(BbcLandingPage.java:61)
at steps.BBC_Steps.iCanViewThe(BBC_Steps.java:37)
at ?.I can view the News(classpath:features/bbc.feature:11)


A
Ashish Thakur Replied on 22/05/2019

please check BbcLandingPage.java line number 61 and BBC_Steps.java line number 37 for the possible error.

 

Additionally try updating the driver as well as browser.