質問

I am trying to test a website. I am able to access most web elements, except the menu items.

Basically there is a drop-down menu, I managed to click on the menu using Selenium, thus opening the drop down menu. Now I need to click on an element in the menu, but the menu seems to be written in Javascript, not as web elements, so I cannot find a way to access the menu items.

Any Ideas? I specifically need to do this in Selenium.

UPDATE: -------------------------------------------------------------------------------------- The menu on the website might be a context menu. It is opened using the left click. Any ideas how I can access its options?

役に立ちましたか?

解決 4

I have not managed to access the menu items using Selenium other than by clicking the menu, and scrolling through the items using up and down arrows through selenium.

I used OpenScript in order to record/playback the test, and it has worked. In my particular case, the website I was using required a flag to be set to make it testable. If you're encountering problems with testing a website, you might need to contact the developers and ask whether an "automation" flag has been set.

他のヒント

The menu may be constructed and manipulated with the page's javascript, but it will exist as html. You can interact with this html using Selenium.

 WebElement dropDownListBox = driver.findElement(By.id("Menu_id")); 
                  Select clickThis = new Select(dropDownListBox);                
                  clickThis.selectByVisibleText(activity); //If you know visible text
                //clickThis.getFirstSelectedOption();  // This will auto select first option in the drop down                
               // clickThis.selectByValue(1); //if you the value of drop down list items

Opening a contextmenu isn't that easy. Till now, I'm triggering an mouse-event via execution of a javascript (didn't find an other solution). It's simular to that discussion: Trigger right-click or Selenium 2 right-click

Sometimes it's useful, if you are are just triggering the underlying js-function. Most of the time the developer can give you one entrypoint to call. This will give you the possibility to keep on building your tests and after some time you implemented the javascript function which opens the contextmenu via triggering the event.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top