请帮助我,我坚持可能很简单的任务。我正在学习webdriverjs,所以我写了一个小代码来在FitBit网站上注册一个帐户:www.fitbit.com/signup,在输入我的电子邮件和密码之后,有一个div弹出窗口并要求用户填写所有必填项目。问题来了,我不能在“名字”字段上“发送密码”或“点击”,你能帮帮我吗?
我的代码非常简单:
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('thisisatest@yopmail.com');
//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');
答案 0 :(得分:1)
根据这是弹出窗口,框架还是其他窗口,您需要使用不同的SwitchTo()命令。请参阅:http://toolsqa.com/selenium-webdriver/switch-commands/或此处:http://learn-automation.com/handle-frames-in-selenium/
现在您添加了HTML,很明显您无需切换即可填写弹出字段。我将您的代码翻译为C#并使用Chromedriver而不是Firefox,并且没有填写Firstname和Lastname的问题。所以基本上你的代码没有任何问题。
您收到任何错误消息吗?
答案 1 :(得分:0)
这里没有窗口,这是一个标签,我在这里发布了它的源代码供您参考
<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"> </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>