When working with a large grid and trying to find an element using XPath, I encountered some difficulties. The XPath used was:
By.xpath("//div[contains(text(),'" +EnteredCompetitionName+ "')]/preceding- sibling::div[contains(concat(' ', @class, ' '), ' slick-cell l0 r0 ')]/a/img"
Due to the size of the grid, simply finding the element by XPath became problematic. In attempt to solve this issue, I turned to using the JavaScript executor in Selenium webdriver.
WebElement selectedCompGlass = (WebElement) js.executeScript("return document.evaluate('//div[contains(text(),' +EnteredCompetitionName+ ')]/preceding-sibling::div[contains(concat(\' \', @class, \' \'), \' slick-cell l0 r0 \')]/a/img' ,document, null, XPathResult.ANY_TYPE, null ).singleNodeValue;");
js.executeScript("arguments[0].click();", selectedCompGlass);
Despite utilizing the JavaScript executor, an error persisted:
missing ) after argument list Command duration or timeout: 8 milliseconds Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:02:37'