click on an expand & collapse button selenium cucumber eclipse

rtgrt

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;
rtgrt

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.

edited at
0

Comments

0 comments
Login to comment

Related

Expand and collapse Relativelayout by button click

How to perform 'Expand' and 'Collapse' in Kendo Tree View on click of Expand button and Collapse button

Expand and Collapse first row on button click Objective - C

javascript expand/collapse button

Dynamically expand/collapse on click of header

Expand button dissapear while collapse

Expand and collapse a colapsingToolBar with a button in Kotlin

Expand and collapse rows through a button

Expand collapse button for multiple sets

Twitter Bootstrap button click to toggle expand/collapse text section above button

Show hidden label by button click inside tableView Cell (expand/collapse cell)

selenium expand collapse treeview C#

How to expand and collapse table row on click

Flutter- ExpansionTile expand and collapse on click

jQuery collapse and expand table rows on click chevron

Expand/collapse div on click for multiple div

Expand/Collapse shiny box on header click

Expand and collapse ul when click caret

Navbar collapse on data-target does not collapse/expand on click

How to toggle expand/collapse behavior by one button?

Datatable button expand/collapse row JQuery

How to hide expand/collapse button in Virtual Treeview?

Expand/Collapse tableview cell with show/less button

Expand and collapse treeview using button | Vuetify

Expand tableview cell on button click

How can I click on an expand button based on criteria using another column with Python and Selenium?

Selenium click GDPR click button

Python Selenium Click button by

How to click on a button with Selenium?