Reputation: 672
I am not able to find input text element in selenium facebook webdriver.
I want it to run further even if it is not able to find the text input. I am using the following code but not working :
if(count($driver->findElement(WebDriverBy::id('custname'))) > 0){
$driver->findElement(WebDriverBy::id('custname'))->sendKeys("John Doe");
}
Actually the problem is if there is data in server it won't show an input text, it just shows a span tag. but if there is no data in server it shows input text. that's why i just want to check if input text exists then insert data in input else continue.
The error is : Fatal error: Uncaught Facebook\WebDriver\Exception\NoSuchElementException: no such element: Unable to locate element:
Upvotes: 0
Views: 278
Reputation: 16307
use Facebook\WebDriver\Exception\NoSuchElementException;
try {
$search = $driver->findElement(WebDriverBy::id('custname'));
} catch (NoSuchElementException $e) {
echo "Not found";
}
Upvotes: 2
Reputation: 17604
You can check if the element is visible:
$userName = $driver->findElement(WebDriverBy::id('custname'));
if ($userName->isVisible()) {
$userName->sendKeys("John Doe");
}
Upvotes: 0