I am trying to click on an expand/collapse button and my first code is working for one of the buttons but somehow it is not working for the other two. It is the same structure that is why it is making this as a strange problem.
Html 1
<!-- language: lang-html -->
<button class="collapser__header collapsed " type="button" data-toggle="collapse" data-target="#collapseIndkomstrubrikker" aria-expanded="false" aria-controls="collapseIndkomstrubrikker">Anden indkomst</button>
<div class="collapse" id="collapseIndkomstrubrikker"></div>
<!-- end snippet -->
Code which is not working
case "Anden indkomst":
try {
WebElement wb;
JavascriptExecutor js = (JavascriptExecutor)driver;
wb = driver.findElement(By.xpath("//*[@data-target='#collapseIndkomstrubrikker']"));
js.executeScript("arguments[0].click();", wb);
} catch (Exception b) {
throw new NoSuchElementException("kunne ikke finde " + knap);
}
break;
Html 2
<button class="collapser__header collapsed " type="button" data-toggle="collapse" data-target="#collapseFradragrubrikker" aria-expanded="false" aria-controls="collapseFradragrubrikker">Andre fradrag</button>
<div class="collapse" id="collapseFradragrubrikker"></div>
Code 2 which is working
case "Andre fradrag":
try {
WebElement wb;
JavascriptExecutor js = (JavascriptExecutor)driver;
wb = driver.findElement(By.xpath("//*[@data-target='#collapseFradragrubrikker']"));
js.executeScript("arguments[0].click();", wb);
} catch (Exception b) {
throw new NoSuchElementException("kunne ikke finde " + knap);
}
break;
There was smth wrong with my Eclipse which is the reason why my code didn't work in the first place. When I restarted Eclipse the code worked:)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments