Closed aurelijusrozenas closed 5 years ago
I'm not a Panther user, but I know there is the method Crawler#selectButton()
:
$button = $crawler->selectButton('the text in your button');
// $button is a Crawler instance
But the method Client#click()
does not seems to accept a button, only links...
Instead, you can probably use the method Client#executeScript
like this:
$client->executeScript("document.querySelector('button').click()");
@Kocal you, sir, are gold!
Hi, Got the same problem but when using your code i have the following exception ::
StateElementReferenceException : stale element reference: element is not attached to the page document
I tried to wait for the button with the following code :
$client-> waitFor('.button');
$client->executeScript("document.querySelector('.button').click()");
but i can't get it to work... Any idea please ?
@Gobmichet I do not think this anything to do with this code, I'd suggest you try to google panther StateElementReferenceException
or webdriver StateElementReferenceException
. Maybe this would have some clues.
Thanks, I'll have a look ^^ Can i ask u some advice about another problem i have with symfony/panther here please ? https://github.com/symfony/panther/issues/183
what's more, i had a look to the link u gave N tried a for() in order to "retry". but same error...
Just in case someone needs help. I had a case where I had a form and a button. I filled a form and clicked on button. Then new page opened. I needed to get data from new page. This is how I did it:
$url = "https://someurl";
$crawler = $this->client->request('GET', $url); //$this->client is Symfony\Component\Panther\Client
$form = $crawler->filter('#Form1')->form();
$form->setValues([
'someField' => 12183,
]);
//This is where I executed JS script to click on a button
$client->executeScript("document.querySelector('#btnSpecial').click()");
//wait for new element on new page to appear
$this->client->waitFor('#results');
//refresh crawler so you can crawl newly loaded page
$crawler = $client->refreshCrawler();
//now crawl new page
$crawler = $client->refreshCrawler();
method really help when you dealing with form elements as well...
Hi,
I have popup with button for JS, so no form or link. I could not find a way to make panther client to click it. Is this (for some reason) not implemented or should I use some other technique (load custom JS maybe).