3

I have problem to reuse selenium session object in 2 function of my code. how can i do that? first function called and it's show the result. then second function called from html post method. how can run selenium in second function with first function session? thanks

$webdriver = new WebDriver("localhost", "4444");
$webdriver->connect("firefox");
$webdriver->get("http://AAA.AAA");
//here with some method i store picture of captcha to show 
echo '<form  method="post" action="process.php">
<table class="table">
    <tr>
        <td>Enter value of picture
            <img src="thumb.jpeg">
        </td>
        <td>
            <input type="text" name="captcha" dir="ltr">
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <button class="submit">Send</button>
        </td>
    </tr>
</table>
</form>';

And process.php it's like this ( second function )

$webdriver->findElementBy("id","username")->sendKeys("XXX");
$webdriver->findElementBy("id","password")->sendKeys("YYYY");
$webdriver->findElementBy("id","captcha")->sendKeys($_POST['captcha']);    
$webdriver->findElementBy("id","submit")->click();

but $webdriver in second function is not defined, and it must have same session id with $webdriver in first function How Can I Do That?

4
  • If you can get the session id before clicking Submit button, jQuery or similar can append a hidden element to the form, value of which could be the session ID. Then on process.php check value of the POST var value. Commented May 1, 2015 at 14:49
  • This may help in concept ontestautomation.com/… even though the code language is Java Commented May 1, 2015 at 15:01
  • no i can't get the session. and i'm sure it's not work, selenium session is object with resource id . it's not possible to send this with hidden value Commented May 1, 2015 at 15:28
  • 1
    Please see accepted answer here: stackoverflow.com/questions/5940214/… Commented May 1, 2015 at 15:47

1 Answer 1

1

keeping selenium browser open with phpunit/selenium shows a Webdriver option -browserSessionReuse

Suggest reading all answers on that page, it may serve helpful.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.