Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check if element is present in laravel dusk test?

Tags:

laravel-dusk

In the below code, I want to check if the element is present at XPath, then only it should execute code.

if($browser->driver->findElement(WebDriverBy::xpath('/html/body/div[1]/div/section/div[3]/div[2]/div/table/tbody/tr['.$i.']/td[2]'))!==null) 
{ 
    $sort=$browser->driver->findElement(WebDriverBy::xpath('/html/body/div[1]/div/section/div[3]/div22]/div/table/tbody/tr['.$i.']/td[2]'))->gettext();
echo $sort; 
}

Or else please suggest if there is another way to check element is present in laravel dusk. P.S. I tried whenAvailable method but it couldn't help me in this case.

like image 261
Rushi Avatar asked Jan 04 '23 22:01

Rushi


1 Answers

Found another better and workable solution:

if ($browser->element('#IDString')) {
}
like image 51
Mark Khor Avatar answered Jan 06 '23 12:01

Mark Khor