bacngao
bacngao

Reputation: 13

Cannot find web element on div popup when using nodejs and webdriverjs

Please help me, I stuck at likely simple task. I'm learning to webdriverjs , so I wrote a small code to register an account on FitBit site at url: www.fitbit.com/signup, after input my email and password, there is an div popup show up and ask user to fill all required field. Problem comes here, I cannot 'sendkeys' or 'click' on First Name field, could you please help me out?

my code is very simple:

const webdriver = require('selenium-webdriver');

const driver = new webdriver.Builder()
    .forBrowser('firefox')
    .build();

const By = webdriver.By; 


// ask the browser to open a page
driver.navigate().to('https://www.fitbit.com/signup');
//Enter Email
driver.findElement(By.className('field email')).sendKeys('[email protected]');
//Enter Password
driver.findElement(By.className('field password')).sendKeys('Abcd1234');
//Check check box
driver.findElement(By.id('termsPrivacyConnected')).click();


//Click Continue button
driver.findElement(By.xpath("//button[@type='submit'  and @tabindex='16']")).click();



//Input First Name
driver.sleep(3000);

driver.findElement(By.xpath('//input[@id="firstName"]')).click();
driver.findElement(By.xpath('//input[@id="firstName"]')).sendKeys('why not input');

Upvotes: 0

Views: 328

Answers (2)

Frank
Frank

Reputation: 871

Depending on if this is a popup, a frame or another window you need a different SwitchTo() command. See: http://toolsqa.com/selenium-webdriver/switch-commands/ or here: http://learn-automation.com/handle-frames-in-selenium/

Now you added your HTML it is clear that that you don't have to Switch to fill in the popup fields. I translated your code to C# and use Chromedriver instead of Firefox and there where no problems filling in the Firstname and Lastname. So basicly nothing is wrong with your code.

Are you getting any error messages?

Upvotes: 1

bacngao
bacngao

Reputation: 1

There is no window here, that's a tag, I posted its source code here for your reference

<section class="wrapper profile common-form">

  <div class="panel panel-profile">

    <h1 class="headline">
      Tell Us About Yourself
    </h1>

    <p class="explain">
      We use this information to improve accuracy.
    </p>

    <form method="post" autocomplete="off" name="completeProfile" action="https://www.fitbit.com/user/profile/complete" id="completeProfile" class="form">
      <input name="_eventName" type="hidden" value="signupAndCompleteProfile" />
      <input name="redirect" type="hidden" value="" />
      <input name="csrfToken" type="hidden" value="84764c8b4da04c85a4541e49947240d0" />


      <fieldset class="info-personal">
        <dl class="field-group">


          <dd class="left-cell">

            <label class="field-label">
                                            Name
                                        </label>
            <input autocomplete="off" tabindex="1" name="firstName" id="firstName" placeholder="First Name" type="text" class="field firstName" />
          </dd>
          <dd class="right-cell">

            <label class="field-label">&nbsp;</label>
            <input autocomplete="off" tabindex="1" name="lastName" id="lastName" placeholder="Last Name" type="text" class="field lastName" />
          </dd>

        </dl>

        <div class="clear"></div>
      </fieldset>
</section>

Upvotes: 0

Related Questions