【发布时间】:2015-05-01 23:51:37
【问题描述】:
我在代码的 2 个函数中重用 selenium 会话对象时遇到问题。我怎样才能做到这一点? 调用第一个函数并显示结果。然后从 html post 方法调用第二个函数。如何在第一个函数会话的第二个函数中运行 selenium? 谢谢
$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>';
而process.php是这样的(第二个函数)
$webdriver->findElementBy("id","username")->sendKeys("XXX");
$webdriver->findElementBy("id","password")->sendKeys("YYYY");
$webdriver->findElementBy("id","captcha")->sendKeys($_POST['captcha']);
$webdriver->findElementBy("id","submit")->click();
但是第二个函数中的 $webdriver 没有定义,它必须与第一个函数中的 $webdriver 具有相同的会话 id 我该怎么做?
【问题讨论】:
-
如果您可以在点击提交按钮之前获得会话ID,jQuery或类似的可以在表单中附加一个隐藏元素,其值可以是会话ID。然后在
process.php上检查 POST var 值的值。 -
这可能有助于概念 ontestautomation.com/… 即使代码语言是 Java
-
不,我无法获得会话。我确定它不起作用,selenium session 是具有资源 id 的对象。无法以隐藏值发送此内容
-
请在此处查看接受的答案:stackoverflow.com/questions/5940214/…