Php 为什么Selenium表单提交返回时缺少所有字段?
最近的编辑::找到问题的解决方案 事实证明,我对submit按钮使用了错误的元素id,因为我认为页面上只有一个表单。。但在底部有第二个单程下降,我没有看到。所以我认为我的问题一方面可能不相关也不正确 然而,我认为下面@Purus的回答很有价值,因为它指出在Se中,表单应该使用->submit()提交,元素应该使用->click() 原创帖子 我正在为基于Drupal的网站编写Se(Selenium)测试工具。我遇到了这个我不理解的问题。事情是这样的:Php 为什么Selenium表单提交返回时缺少所有字段?,php,drupal,selenium,Php,Drupal,Selenium,最近的编辑::找到问题的解决方案 事实证明,我对submit按钮使用了错误的元素id,因为我认为页面上只有一个表单。。但在底部有第二个单程下降,我没有看到。所以我认为我的问题一方面可能不相关也不正确 然而,我认为下面@Purus的回答很有价值,因为它指出在Se中,表单应该使用->submit()提交,元素应该使用->click() 原创帖子 我正在为基于Drupal的网站编写Se(Selenium)测试工具。我遇到了这个我不理解的问题。事情是这样的: 我有一个脚本,可以登录并导航到创建用户页面
require_once './path_config.php';
class FormDemoTest extends PHPUnit_Framework_TestCase
{
public static $LOGIN_PAGE_URL = 'https://dev.abc.com/login/';
public static $FORM_PAGE_URL = 'https://dev.abc.com/create-user';
var $driver;
public function setUp()
{
$host = 'http://localhost:4444/wd/hub'; // this is the default
$capabilities = DesiredCapabilities::firefox();
$this->driver = RemoteWebDriver::create($host, $capabilities, 5000);
}
public function tearDown()
{
$this->driver->quit();
parent::tearDown();
}
public function testCreateForm()
{
$id = 'jules';
$pwd = '22';
$this->driver->get(self::$LOGIN_PAGE_URL);
$this->findElementById('login')->sendKeys($id);
$this->findElementById('pwd')->sendKeys($pwd);
$this->findElementById('submit')->click();
sleep(1);
$this->driver->get(self::$FORM_PAGE_URL);
$this->findElementById('first')->sendKeys('abc');
$this->findElementById('last')->sendKeys('efg');
$this->findElementById('submit')->click();
$expectedTitle = "Create User";
self::assertEquals($expectedTitle, $this->driver->getTitle());
}
public function findElementById($id=null) {
return $this->driver->findElement(WebDriverBy::id($id));
}
}
感谢您查看对于表单,单击和提交是不同的 是否可以尝试提交()而不是单击() 与此相反:
$this->findElementById('submit')->click();
试试这个:
$this->findElementById('login')->submit();
submit()方法提交表单,您可以从任何元素调用它,并提交相应的值。您在这里提出了一个重要的观点,即存在submit()方法,这就是表单应该使用的方法;谢谢你的洞察力。不幸的是,我仍然看到同样的问题——提交表单会重新加载我输入为空的字段的页面。我对代码所做的唯一更改是按照您的建议,将对->click()的调用更改为->submit()。奇怪的情况在我看来?!有我要检查的url吗?嗨@Purus,我正在等待项目经理的批准。共享一个url。我感谢你对这条线索的关注。再保险。那很好。