-1

I am using Selenium Webdriver in C#. I am trying to find the element for below given Angular code.

"<div class="ViewMenu" ng-class="{'selectedViewMenu':SearchObj.param.View=='Videos'}" style="">Videos</div>"

I tried it using driver.FindElement(By.XPath("//div[@class='ViewMenu selectedViewMenu']"));

but it doesn't work.

  • what you have to do with this? Is it dropdown list/textbox/button? which environment you are using to run this script? Selenium V-? browser-? paste error msg that your IDE shows. – Bharat Mane Apr 26 '16 at 12:15
  • I recommend removing selectedViewMenu from your selector. It may not hurt but it definitely will not help. – user246 Apr 27 '16 at 12:17
3

Check with different XPath-

XPath 1:

//div[@class='ViewMenu selectedViewMenu']

XPath 2:

//*[@class='ViewMenu selectedViewMenu']

OR Try with CSS Selector:

driver.FindElement(By.cssSelector(".ViewMenu.selectedViewMenu"));
1

one choice by CLASS:

driver.findElement(By.className("element class"))

another choice: by css selector (you need to work on css selector)

driver.findElement(By.cssSelector("css selector"))

driver.findElement(By.cssSelector("ng-class["\{\'selectedViewMenu\'\:SearchObj.param.View=='Videos'\}]")
0

Use this xpath: //div[@class='ViewMenu' and text() = 'Videos'] because class selectedViewMenu is probably only when element is selected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.