-1

In my scenario I have multiple classes using

 driver.Navigate().GoToUrl("URL");
            driver.Manage().Window.Maximize();
            driver.FindElement(By.Id("userName")).SendKeys("jordan");
            driver.FindElement(By.Id("password")).SendKeys("54321" + Keys.Enter);
            driver.FindElement(By.ClassName(""));

When I execute the line

driver.FindElement(By.ClassName(""));

I get Exception Error

Source Code:

<a class="hr" href="URL">
                        <div class="foo pixelated">
                            <img class="hr_resp" src="/Content/images/splash-images/icon_hr.png" style="margin-top:25px;">
                            <img class="hr_resp" src="/Content/images/splash-images/icon_hr_hub1.png" style="margin-top:25px;">
                        </div>
                        <p>Hr Managment</p>
                    </a>
8
  • Can you please add the detail question, no one of us will be able to answer question without any resources provided by you. Jan 16, 2018 at 10:44
  • 1
    please consider reading the guidelines on asking a good question , you haven't provided enough info and you have assumed your urgency applies to others.
    – Amias
    Jan 16, 2018 at 10:54
  • Would you please add more details? like what is programming language you use and sample code that you are trying to execute it. Jan 16, 2018 at 11:07
  • 1
    What is the error text? Without knowing what error you are getting there is not enough information to answer your question.
    – Kate Paulk
    Jan 16, 2018 at 12:37
  • Error: Unable to locate element: hr
    – user30347
    Jan 16, 2018 at 12:58

4 Answers 4

3

driver.FindElement(By.ClassName("")) - you need to provide a class name. Your argument is empty, obviously it cannot find it.

1

If you have doubt about using the driver.findElement(By.ClassName(//class name of the element)) please use the below link it's described how to find element using the class name

Blog link-softwaretestingmaterial

Git hub-seleniumhq.github

Initially search your question if any other questions answers are posted related to your asking question in before post your question.

0

Try to comment/delete this line driver.FindElement(By.ClassName("")); As I think it is not doing any thing in your code.

Before trying to find the element wait for it to get loaded. You can do that by using

  1. Thread.sleep() [Which is not advisable]
  2. You can use WebDriverWait to check whether the element is loaded or not. Then do a driver.findelement()

Always ask question with all the relevant details or else others will not be able to help. Go through this link how to ask question

0

Would you please try this :

driver.FindElement(By.XPath(""));

If you use chrome, in the source code, right click on the line "<div class="foo pixelated"> and choose copy then copy XPath and paste it above.

1
  • Thank you for your suggestion but I am not using but I am not using XPath
    – user30347
    Jan 16, 2018 at 13:39

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