如何用ChromDriver和yii2解决"element not interactable"?
How to solve "element not interactable" with ChromDriver and yii2?
起初我使用 OpenServer 并像这样使用 ChromeDriver
D:\ChromeDriver\chromedriver.exe --url-base=/wd/hub
我的Acceptance.suite.yml
class_name: AcceptanceTester
modules:
enabled:
- WebDriver:
url: http://arctic/
window_size: false # disabled in ChromeDriver
port: 9515
browser: chrome
- Yii2:
part: orm
entryScript: index-test.php
cleanup: false
我的验收测试
public function _before(AcceptanceTester $I)
{
$I->amOnPage('/admin');
$I->fillField('FormLogin[username]', 'admin');
$I->fillField('FormLogin[password]', 'admin');
$I->click('Войти');
$I->click('Меню');
}
我遇到了这个错误
1) AdminMenuAcceptCest: Try to test
Test tests\acceptance\AdminMenuAcceptCest.php:tryToTest
[Facebook\WebDriver\Exception\ElementNotInteractableException] element not interactable
(Session info: chrome=80.0.3987.100)
Scenario Steps:
2. $I->fillField("FormLogin[username]","admin") at tests\acceptance\AdminMenuAcceptCest.php:8
1. $I->amOnPage("/admin/main") at tests\acceptance\AdminMenuAcceptCest.php:7
#1 D:\OSPanel-new\domains\arctic_dev\vendor\php-webdriver\webdriver\lib\Exception\WebDriverException.php:95
#2 D:\OSPanel-new\domains\arctic_dev\vendor\php-webdriver\webdriver\lib\Remote\HttpCommandExecutor.php:370
#3 D:\OSPanel-new\domains\arctic_dev\vendor\php-webdriver\webdriver\lib\Remote\RemoteWebDriver.php:584
#4 D:\OSPanel-new\domains\arctic_dev\vendor\php-webdriver\webdriver\lib\Remote\RemoteExecuteMethod.php:27
#5 D:\OSPanel-new\domains\arctic_dev\vendor\php-webdriver\webdriver\lib\Remote\RemoteWebElement.php:60
#6 Codeception\Module\WebDriver->fillField
#7 D:\OSPanel-new\domains\arctic_dev\tests\_support\_generated\AcceptanceTesterActions.php:1505
#8 D:\OSPanel-new\domains\arctic_dev\tests\acceptance\AdminMenuAcceptCest.php:8
#9 AdminMenuAcceptCest->_before
我试图检查 $I->seeElement()
中是否存在字段,但没有看到。
这可能对某人有帮助,这是我的解决方案:
public function _before(AcceptanceTester $I)
{
$I->amOnPage('/admin');
$I->executeInSelenium(function(\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) {
$webdriver->executeScript("$('#login_block').modal('show');");
});
$I->wait(5);
$I->fillField('FormLogin[username]', 'admin');
$I->fillField('FormLogin[password]', 'admin');
$I->click('Войти');
}
起初我使用 OpenServer 并像这样使用 ChromeDriver
D:\ChromeDriver\chromedriver.exe --url-base=/wd/hub
我的Acceptance.suite.yml
class_name: AcceptanceTester
modules:
enabled:
- WebDriver:
url: http://arctic/
window_size: false # disabled in ChromeDriver
port: 9515
browser: chrome
- Yii2:
part: orm
entryScript: index-test.php
cleanup: false
我的验收测试
public function _before(AcceptanceTester $I)
{
$I->amOnPage('/admin');
$I->fillField('FormLogin[username]', 'admin');
$I->fillField('FormLogin[password]', 'admin');
$I->click('Войти');
$I->click('Меню');
}
我遇到了这个错误
1) AdminMenuAcceptCest: Try to test
Test tests\acceptance\AdminMenuAcceptCest.php:tryToTest
[Facebook\WebDriver\Exception\ElementNotInteractableException] element not interactable
(Session info: chrome=80.0.3987.100)
Scenario Steps:
2. $I->fillField("FormLogin[username]","admin") at tests\acceptance\AdminMenuAcceptCest.php:8
1. $I->amOnPage("/admin/main") at tests\acceptance\AdminMenuAcceptCest.php:7
#1 D:\OSPanel-new\domains\arctic_dev\vendor\php-webdriver\webdriver\lib\Exception\WebDriverException.php:95
#2 D:\OSPanel-new\domains\arctic_dev\vendor\php-webdriver\webdriver\lib\Remote\HttpCommandExecutor.php:370
#3 D:\OSPanel-new\domains\arctic_dev\vendor\php-webdriver\webdriver\lib\Remote\RemoteWebDriver.php:584
#4 D:\OSPanel-new\domains\arctic_dev\vendor\php-webdriver\webdriver\lib\Remote\RemoteExecuteMethod.php:27
#5 D:\OSPanel-new\domains\arctic_dev\vendor\php-webdriver\webdriver\lib\Remote\RemoteWebElement.php:60
#6 Codeception\Module\WebDriver->fillField
#7 D:\OSPanel-new\domains\arctic_dev\tests\_support\_generated\AcceptanceTesterActions.php:1505
#8 D:\OSPanel-new\domains\arctic_dev\tests\acceptance\AdminMenuAcceptCest.php:8
#9 AdminMenuAcceptCest->_before
我试图检查 $I->seeElement()
中是否存在字段,但没有看到。
这可能对某人有帮助,这是我的解决方案:
public function _before(AcceptanceTester $I)
{
$I->amOnPage('/admin');
$I->executeInSelenium(function(\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) {
$webdriver->executeScript("$('#login_block').modal('show');");
});
$I->wait(5);
$I->fillField('FormLogin[username]', 'admin');
$I->fillField('FormLogin[password]', 'admin');
$I->click('Войти');
}