Andrew
Andrew

Reputation: 98

Cannnot click a href

Hi i have the following code

<!DOCTYPE html>
<html lang="en">
<head>
<body class="skin-blue sidebar-mini">
<div class="wrapper">
<header class="main-header">
<aside class="main-sidebar">
<section class="sidebar" style="height: auto;">
<div class="user-panel"> </div>
<br>
<br>
<br>
<ul class="sidebar-menu">
<li class="treeview">
<a href="../user/account">
<i class="fa fa-edit"></i>
<span>Basic Information</span>
</a>
</li>
<li class="treeview">
<a href="../admin/myproperties">
<i class="fa fa-list"></i>
<span>My Hotel</span>
</a>
</li>
</ul>
</section>
</aside>

The nightwatch code i use is this and the error is that it cant locate the element. In other site this would just work fine but here it is like it buggs

 module.exports = {
  tags: [''],
  'extranet' : function (client) {
    client
      .url('www.somesite.com')
      .waitForElementVisible('body', 1000)

      // --Log In Form //
      //.click('a[class="btn btn-block btn-social btn-lg btn-google"]')
      .setValue('input[name=email]', '[email protected]')
      .setValue('input[name=password]', 'password')
      .click('button[type="submit"]')

      .click('a[href="../user/account"]')

SOLUTION: Kishan Patel helped a lot so here is the Nighwatch.js that is clicking this element using Xpath

module.exports = {
  tags: [''],
  'extranet' : function (client) {
    client
      .url('www.somesite.com')
      .waitForElementVisible('body', 1000)
      .setValue('input[name=email]', '[email protected]')
      .setValue('input[name=password]', 'password')
      .click('button[type="submit"]')
      .waitForElementVisible('section[class="sidebar"]', 10000)
      .useXpath()
      .click('html/body/div[1]/aside/section/ul/li[1]/a')
      .pause(5000)
      .end();

  }
};

Upvotes: 0

Views: 851

Answers (2)

Rita
Rita

Reputation: 53

First of all sorry for using this section to make a comment but I don´t have enough reputation to do so. @Kishan Patel : could you please have a look on my issue? Loop is not working properly - nightwatch

Upvotes: 0

Kishan Patel
Kishan Patel

Reputation: 1383

Just try the below code . You apply some wait after hitting submit and it will get resolved. I ran the same code in JAVA successfully .

WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();

driver.get("http://example.com");

//Login Username

driver.findElement(By.xpath("html/body/div[1]/div/div[2]/form/div[3]/input")).sendKeys("e-mail");

//Password

driver.findElement(By.xpath("html/body/div[1]/div/div[2]/form/div[4]/input")).sendKeys("password");

//Hit on submit

driver.findElement(By.xpath("html/body/div[1]/div/div[2]/form/div[5]/div/button")).click();

//Wait for element to be visible

WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("html/body/div[1]/aside/section/ul/li[1]/a")));

//Click on the href="../user/account"

driver.findElement(By.xpath("html/body/div[1]/aside/section/ul/li[1]/a")).click();

Upvotes: 1

Related Questions