Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用凭据填充浏览器验证弹出窗口_Php_Selenium_Selenium Chromedriver - Fatal编程技术网

Php 如何使用凭据填充浏览器验证弹出窗口

Php 如何使用凭据填充浏览器验证弹出窗口,php,selenium,selenium-chromedriver,Php,Selenium,Selenium Chromedriver,我试图在php中使用selenium填充这个弹出窗口 我试过这个 $driver->get("http://example.com"); $driver->wait(10); $driver->action()->sendKeys('username'); 但什么也没有填满 我犯了这个错误 Fatal error: Uncaught TypeError: Argument 1 passed to Facebook\WebDriver\Interact

我试图在php中使用selenium填充这个弹出窗口 我试过这个

$driver->get("http://example.com");
$driver->wait(10);
$driver->action()->sendKeys('username');
但什么也没有填满

我犯了这个错误

Fatal error: Uncaught TypeError: Argument 1 passed to Facebook\WebDriver\Interactions\WebDriverActions::sendKeys() must be an instance of Facebook\WebDriver\WebDriverEle
ment or null, string given, called in C:\wamp64\www\new\test.php on line 87 and defined in C:\wamp64\www\new\vendor\facebook\webdriver\lib\Interactions\WebDriverActions.
php:269

当你在做
get()
时,也要确保通过信用卡

$driver->get("http://UserName:Password@Example.com");
请确保像这样使用SendKey:

$driver->get("https://www.google.com/ncr");
$driver->manage()->window()->maximize();
sleep(5);
$element = $driver->findElement(WebDriverBy::name("q"));
$element->sendKeys("LambdaTest");
更新:

// use this expected condition to switch the control to alert

$driver->wait()->until(WebDriverExpectedCondition::alertIsPresent());
$driver->switchTo()->alert()->sendKeys('username' + Keys.TAB + 'password');
$driver->switchTo()->alert()->accept();
 $driver->wait()->until(WebDriverExpectedCondition::alertIsPresent());
 $driver->switchTo()->alert()->sendKeys('username');
 $driver->getKeyboard()->pressKey(WebDriverKeys::TAB);
 $driver->switchTo()->alert()->sendKeys('password');
 $driver->switchTo()->alert()->accept();
更新2:

// use this expected condition to switch the control to alert

$driver->wait()->until(WebDriverExpectedCondition::alertIsPresent());
$driver->switchTo()->alert()->sendKeys('username' + Keys.TAB + 'password');
$driver->switchTo()->alert()->accept();
 $driver->wait()->until(WebDriverExpectedCondition::alertIsPresent());
 $driver->switchTo()->alert()->sendKeys('username');
 $driver->getKeyboard()->pressKey(WebDriverKeys::TAB);
 $driver->switchTo()->alert()->sendKeys('password');
 $driver->switchTo()->alert()->accept();
看起来你的“登录”弹出窗口是Chrome的基本认证弹出窗口。这不是“警报”框,也不是实际的HTML元素,因此不能使用sendKeys()向其发送击键


cruisepandey的$driver->get(“http://UserName:Password@不过,这个建议应该是可行的。注意,我认为这些天,”http://UserName:Password@com“仅适用于硒;它不能直接在Chrome地址栏中作为URL使用。

错误是什么?我更新了问题我尝试了此操作,但它要求提供可以访问站点的凭据。请注意,您使用的sendKeys如下所示
$driver->action()->sendKeys('username')但是你需要有网络定位器才能发送钥匙,对吗?否则,您需要切换到alert,然后发送keysCool,但我如何才能在弹出窗口中选择输入?查看更新的代码我很感激您的时间,但在(WebDriverExpectedCondition::alertIsPresent())之前,它等待的时间太长,无法填充任何内容,因此我尝试删除它并添加1秒等待时间,并且得到了这个错误Facebook\WebDriver\Exception\WebDriverException::ThroweException(27,“没有这样的aler t”