-2

I'm trying to click a button inside a hikvision camera login page using internet explorer ( note that this website only works with IE) with eclipse this is the code for the button

<button class="btn btn-primary login-btn" type="button" ng-click="login()"><label class="ng-binding" ng-bind="oLan.login">Login</label></button>
<label class="ng-binding" ng-bind="oLan.login">Login</label>

Image:

See this Image

This is my code , everything works fine but the button won't click.

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;


public class test {

    public static void main(String[] args) {
        System.setProperty("webdriver.ie.driver","C:\\Users\\SAAD\\Downloads\\IEDriverServer_Win32_4.0.0\\IEDriverServer.exe");
        WebDriver driver = new InternetExplorerDriver();
        driver.get("http://10.67.0.230");
        driver.manage().window().maximize();
        WebElement Username = driver.findElement(By.id("username"));
        Username.click();
        Username.sendKeys("admin");
        WebElement Password = driver.findElement(By.id("password"));
        Password.click();
        Password.sendKeys("ezEqL7?Ss=g");
        WebElement Login = driver.findElement(By.className("btn.btn-primary.login-btn"));
        Login.click();

Also I have tried this xpath but still don't work

WebElement Login = driver.findElement(By.xpath("/html/body/div[1]/table/tbody/tr/td[2]/div/div[5]/button"));
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Saad
  • 1
  • 1
  • What exactly have you tried? What problems faced? – Prophet Feb 14 '22 at 08:03
  • since i'm using IE there are no tools to get the xpath for it , so if you can give me the xpath because im not able to get it also i tried locating the button using it's class but nothing happens – Saad Feb 14 '22 at 08:08
  • Again, please share your code. After that we possibly will be able to help here – Prophet Feb 14 '22 at 08:23
  • 1
    Code added to the question . – Saad Feb 14 '22 at 08:26
  • What is `http://10.67.0.230`? It seems to be some your local address, correct? – Prophet Feb 14 '22 at 08:29
  • yes it's a local camera on my network , but the page opens fine and my sendkeys also works fine , i just need to click the "Login" button , thanks – Saad Feb 14 '22 at 08:32

1 Answers1

0

The desired element is a Angular element, so to click() on the element you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following locator strategies:

  • cssSelector:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("button.btn.btn-primary.login-btn[ng-click^='login'] > label.ng-binding"))).click();
    
  • xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@class='btn btn-primary login-btn' and starts-with(@ng-click, 'login')]/label[@class='ng-binding' and text()='Login']"))).click();
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Still nothing clicks , i tried both lines under "Password.sendKeys("ezEqL7?Ss=g");" – Saad Feb 14 '22 at 09:43
  • What do you mean by _Still nothing clicks_? The code solution is to click on the button element with text as **Login** and have nothing to do with `Username.sendKeys();` or `Password.sendKeys("ezEqL7?Ss=g");` as such. – undetected Selenium Feb 14 '22 at 10:12
  • I mean the login button is still not pressed . – Saad Feb 14 '22 at 10:36