SendKeys of dynamic value Selenium PHP

Hello Guys, Please I have an issue, im working on a web based app login page, the value of password is changing each time so i need to make it dynamic using selenium PHP (sendKeys) Any idea? Any help? Best Regards,

2 Likes

Even if the password is random, you can still use the sendKeys method in Selenium PHP to pass the required password to the appropriate DOM element.

Taking the relevant code snippet from the Selenium PHP tutorial, here is how you can pass the corresponding password string to the Password textbox:

$element_username = $this->webDriver->findElement(WebDriverBy::id("username"));
$element_username->sendKeys($username);

/* The password can be generated randomly but that would not change the overall logic */
$element_password = $this->webDriver->findElement(WebDriverBy::id("password"));
$element_password->sendKeys($password);

/* Click the Submit button */
$element_submit = $this->webDriver->findElement(WebDriverBy::id("subbutton"));
$element_submit->click();

This should do the trick for you since the usecase does not seem to complicated at the first glance. Please let me know if this helps or if you have any further queries.

3 Likes

Thank you so much, I applied your solution by using JSON file which contains the credentials (username & password)

2 Likes