selector - Unable to identify the WebElement using className which has double underscore.(Selenium WebDriver - JAVA) -
i have been trying identify webelement using classname selector contains double underscore , hyphens in (for example: grid__row) when run script get
org.openqa.selenium.nosuchelementexception: no such element: unable locate element. refer below snippet of html content. have highlighted few of tags not able identify.
i not sure whether double underscore / hyphen causing issue or else.
find below code portion did
package sitecore_testscript; import java.util.list; import org.openqa.selenium.by; import org.openqa.selenium.webdriver; import org.openqa.selenium.webelement; import org.openqa.selenium.interactions.actions; import org.testng.annotations.beforetest; import org.testng.annotations.test; import sitecore_framework.browser; public class afhssampletest { webdriver driver; @beforetest public void launchbrowser() { driver = browser.launchgooglechrome("https://www.ashleyfurniturehomestore.com/c/furniture/living-room/sectional-sofas/?icid=meganav-furniture-menu-sectional-sofas"); } @test public void selectproductinsubcatpg() throws interruptedexception{ string itemname = "walworth reclining loveseat"; webelement mainproductlist = driver.findelement(by.classname("main")); list<webelement> productlist = mainproductlist.findelements(by.tagname("li")); for(int = 0; < productlist.size(); i++){ string productname = productlist.get(i).gettext(); if(productname == itemname){ productlist.get(i).click(); } else if(productname != itemname && == (productlist.size() - 1)){ webelement productcontainer = mainproductlist.findelement(by.classname("container")); thread.sleep(5000); webelement gridcol = productcontainer.findelement(by.classname("grid__row")); //throws exception in line onwards. list<webelement> allproducts = gridcol.findelements(by.tagname("a")); for(int j =0; j < allproducts.size(); j++){ string sample = allproducts.get(j).gettext(); system.out.println(sample); // if(allproducts.get(j).gettext() == "click view products"){ // // actions act = new actions(driver); // // act.movetoelement(allproducts.get(j)).build().perform(); // // allproducts.get(j).click(); // // j = allproducts.size(); // } } } } } }
Comments
Post a Comment