Reputation: 43
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!
Upvotes: 4
Views: 3521
Reputation: 193058
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();
Upvotes: 0
Reputation: 4739
You can use like this:
WebELement btnBefore= driver.findElement(By.XPATH("//button[contains(text(),'::before')]");
btnBefore.click();
Upvotes: 1
Reputation: 161
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.
Upvotes: 0