4

I'm doing an automated web test for my job and I'm having trouble with my code. It didn't do anything Here's the code from the website I'm trying to work with:<button class="fa fa-2x sidebar-button pull-left fa-bars" ng-click="offcanvasleft()" ng-class="activeLeft ? 'fa-bars' : 'fa-bars'">::before</button>

And here is my code:driver.findElement(By.cssSelector("//*[@id=\"mainrow\"]/div/div/button[1]")).click();

Can someone help me with this? Thank you!

3 Answers 3

1

You can use like this:

WebELement btnBefore= driver.findElement(By.XPATH("//button[contains(text(),'::before')]");
btnBefore.click();
Sign up to request clarification or add additional context in comments.

Comments

0

As per the HTML you have shared the WebElement is a Angular Element so you have to induce WebDriverWait with ExpectedConditions clause as elementToBeClickable as follows :

new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@class='fa fa-2x sidebar-button pull-left fa-bars' and starts-with(@ng-class,'activeLeft')]"))).click(); 

Comments

0
driver.findElement(By.XPATH("//button[@class="fa fa-2x sidebar-button pull-left fa-bars]").click();

This is assuming java syntax is right. I write selenium in python mostly.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.