如何使用 Symfony 5 + Panther + Webbrowser + Chrome + set Value + Html + Js 设置输入字段值

How to set input field value using Symfony 5 + Panther + Webbrowser + Chrome + setValue + Hmtl + Js

如何在basic-regular controller中设置而不是TestCase扩展的TestController,设置为Web文本值的输入字段?

    public function automatical_login_with_codes()
{
    $browser = new HttpBrowser(HttpClient::create());
    $client = Client::createChromeClient();
    $jsLink     = "document.querySelector('#ctl00_uxAuthenticationBlock_uxOpenLogin').click()";
    $crawler    = $client->request('GET', 'https://www.best.com/CategoryList.aspx?');
    $client->executeScript($jsLink);
    $client->waitFor('#ctl00_uxAuthenticationBlock_uxLoginText');//        $this->assertSame
    $crawler->filter('#ctl00_uxAuthenticationBlock_uxLoginText')->text('USERNAME'); <<-- NOT SET :(((
$check = $crawler->filter('#ctl00_uxAuthenticationBlock_uxLoginText')->text();
dd($check);  //<- result nothing

答案很简单(我模拟输入浏览器输入字段值 - USERNAME)

$crawler->filter('#ctl00_uxAuthenticationBlock_uxLoginText')->sendKeys('USERNAME');

希望它能节省您的时间:)

另一种方法:

$client->findElement(WebDriverBy::cssSelector('#ctl00_uxAuthenticationBlock_uxLoginText'))->sendKeys('USERNAME');