سؤال

I want be able click on link from drop down using selenium with phpunit. I don't have any idea how make it happens, can anyone show me example or relevant tutorial, post or anything that can help me figure out.

when I try click on the element without put mouse over the drop down I got this error:

Element is not currently visible and so may not be interact with command ....

Thanks.

EDIT: when I said "drop down" I don't mean regular select. it more like popup you can see the example here: http://investing.com

look how they build the menu I want be able click on 'Technical' -> 'Fibonacci Calculator' for example.

هل كانت مفيدة؟

المحلول

Check this post out: Selenium: How to select an option from a select menu?

You can find more info about this here

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.

Credits go to Dave Hunt


What I use:

$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

EDIT: http://www.anitpatel.net/2012/02/25/selenium-webdriver-how-to-click-on-a-hidden-link-or-menu/ This one explains it in java but basically what he does is a mouse over/hover and wait. Then he clicks on the element. I'm not a java genius but it's an example how to work with it.

You can use the:

string mouseOver(string $locator)

This simulates a user hovering a mouse over the specified element. http://docs.tadiavo.com/phpunit/www.phpunit.de/pocket_guide/3.1/en/selenium.html

نصائح أخرى

Check if the element is visible using the xpath of the required option value.

$this->isElementPresent($xpath); $this->click($xpath);

If it is true, then click() method selects the specified option.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top