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

1.8k views Asked by At

how to set in basic-regular controller not TestController which is extended from TestCase, set to input field on Web text value?

    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
2

There are 2 answers

2
Mmx On BEST ANSWER

Answer is very simple (I simulate typing in browser input field value - USERNAME)

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

Hope it save your time :)

0
joan16v On

Another way to do it:

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