rialto-php / puphpeteer

A Puppeteer bridge for PHP, supporting the entire API.
MIT License
1.34k stars 204 forks source link

Using puppeteers page.select() function in puphpeteer #158

Open marcpre opened 2 years ago

marcpre commented 2 years ago

Hello,

I am using "nesk/puphpeteer": "^2.0" and I want to select the following dropdown of a datatable:

image

Find below my minimum example:

<?php

require_once '../vendor/autoload.php';

use Nesk\Puphpeteer\Puppeteer;
use Nesk\Rialto\Data\JsFunction;

$debug = true;

$puppeteer = new Puppeteer([
    'read_timeout' => 100,
    'debug' => $debug,
]);
$browser = $puppeteer->launch([
    'headless' => !$debug,
    'ignoreHTTPSErrors' => true,
]);

$page = $browser->newPage();
$page->goto('https://www.psacard.com/auctionprices#0%7Cpokemon');

// select dropdown
// drop-down activate
$selectElemDropDown = $page->querySelectorXPath('//*[@id="DataTables_Table_0_length"]/label/select');
$selectElemDropDown[0]->click();
$selectElemOptTwo = $page->querySelectorXPath('//*[@id="DataTables_Table_0_length"]/label/select/option[2]');
$selectElemOptTwo[0]->click();

$browser->close();

I tried clicking on the dropdown and then clicking again to select the element, which does not work.

I puppeteer JS there is a function called page.select(selector, ...values).

How can I do this function in puphpteer in my minimum viable example?

I appreciate your replies!

chisphefo commented 2 years ago

Hi, Inspect element "Per Page" in your link given at https://www.psacard.com/auctionprices#0%7Cpokemon

I think you should try Select method by Selector like this:

$page->select('[name="DataTables_Table_0_length"]', '100');

Good luck!