我想要能够点击链接从下拉使用硒与phpunit。我不知道如何使它发生,谁能给我示范或相关的教程,张贴或任何东西,可以帮助我弄清楚。
当我尝试单击元素而没有将鼠标放在下拉菜单上时,我得到了以下错误:
元素当前不可见,因此可能无法与命令.交互。
谢谢。
编辑:当我说“下拉”时,我不是指常规选择。它更像弹出窗口,您可以看到下面的示例:http://investing.com
看看他们如何构建菜单,我想要点击‘技术’->‘’,例如。
发布于 2014-03-19 00:00:22
查看这篇文章:Selenium:如何从选择菜单中选择一个选项?
您可以找到更多关于这个这里的信息。
select(selectLocator, optionLocator)
Arguments:
selectLocator - an element locator identifying a drop-down menu
optionLocator - an option locator (a label by default)
Select an option from a drop-down using an option locator.
Option locators provide different ways of specifying options of an HTML Select element (e.g. for selecting a specific option, or for asserting that the selected option satisfies a specification). There are several forms of Select Option Locator.
label=labelPattern: matches options based on their labels, i.e. the visible text. (This is the default.)
label=regexp:^[Oo]ther
value=valuePattern: matches options based on their values.
value=other
id=id: matches options based on their ids.
id=option1
index=index: matches an option based on its index (offset from zero).
index=2
If no option locator prefix is provided, the default behaviour is to match on label.
给戴夫亨特的学分
我用的是:
$search13 = $this->webDriver->findElement(WebDriverBy::id('id_of_dropdown_field'));
$search13->click(); // Clicking on the dropdownfield
$this->webDriver->getKeyboard()->pressKey('ARROW_DOWN'); // Will go down in your dropdown selection )
sleep(1);
$this->webDriver->getKeyboard()->pressKey('ENTER'); // Enter for submitting your selection
编辑:http://www.anitpatel.net/2012/02/25/selenium-webdriver-how-to-click-on-a-hidden-link-or-menu/,这个是用java解释的,但他所做的基本上是鼠标在/悬停和等待。然后他点击元素。我不是一个java天才,但这是一个如何使用它的例子。
您可以使用:
string mouseOver(string $locator)
这将模拟用户在指定元素上悬停鼠标。指南/3.1/en/selenium.html
发布于 2014-09-23 01:36:14
使用必需选项值的xpath检查元素是否可见。
$this->isElementPresent($xpath); $this->click($xpath);
如果为真,则单击()方法选择指定的选项。
https://stackoverflow.com/questions/22451708
复制