0

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.

Dennis
  • 704
  • 1
  • 9
  • 25

2 Answers2

0

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

Community
  • 1
  • 1
Decypher
  • 690
  • 1
  • 8
  • 30
  • 1
    thanks, but see my edit I don't need the regular select option. (if no one will get right answer soon I will mark your answer as a right answer). – Dennis Mar 19 '14 at 10:34
  • Hmm that's an annoying one, you can click on the menu but then only the side submenu doesn't show in the interface. A fast workaround is going to the URL itself. ' http://www.investing.com/forex-tools/fibonacci-calculator ' this one then. Or you can click on Tools --> shows next interface --> click on 'Trading Calculators ' – Decypher Mar 19 '14 at 11:41
  • the idea is create the test that will be able work with menu changes – Dennis Mar 19 '14 at 12:28
  • Try to use: 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 – Decypher Mar 19 '14 at 13:19
0

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.

Vidz
  • 545
  • 1
  • 6
  • 16