0

enter image description hereI am trying to click on a tab - a rather simple task.But, I get the error message above. I have added a thread.sleep command - in case it is due to synchronization issues. Your help is highly appreciated:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Support.UI;
using System.Globalization;
using System.Threading.Tasks;

namespace CV_Lib_Do_Not_Use
{
    class Program
    {
        static void Main(string[] args)
        {
            //Instantiate Firefox Driver
            //Go to CV Library Website
            var driver = new FirefoxDriver();
            driver.Navigate().GoToUrl("https://www.cv-library.co.uk/");

            //Wait for web element to become visible
            System.Threading.Thread.Sleep(15000);


            //Click on Search Jobs tab
            driver.FindElement(By.XPath(".//*[@id='header-nav-new']/div/div[2]/ul/li[2]/a")).Click();

        }
    }
}

I have checked previous errors from:

Selenium webdriver - Unable to locate element,xpath,error

Selenium Webdriver | Unable to locate element error

The solutions were not helpful.

1

There are no elements matching the XPath expression.

There is actually a much simpler way to locate the "Search Jobs" link - by "id":

driver.FindElement(By.Id("header-link-searchjobs")).click();

Note that, instead of Sleep() call, you should use an Explicit Wait:

var wait = WebDriverWait(driver, TimeSpan.FromSeconds(10))
wait.Until(ExpectedConditions.ElementExists((By.Id("header-link-searchjobs"))).click();
  • That worked!! How did you get "header-link-searchjobs", please ? I can't seem to get it by using firepath / firebug.. Many Thanks – OA345 Jun 28 '17 at 20:07
  • @OA345 just inspected the element with chrome developer tools. Glad to see it helped. Thanks. – alecxe Jun 28 '17 at 20:10
  • I have taken a screen shot of the Chrome Developer. But I could not locate the tag that you suggested earlier. I have attached a screen shot. Please, can you help. Thank you. – OA345 Jun 28 '17 at 20:34
  • @OA345 interesting, your desired element looks in the page source this way <a href="/search-jobs" id="header-link-searchjobs">Search Jobs</a>. Does it look the same to you? – alecxe Jun 28 '17 at 20:37
  • Where exactly in the page / tab are you looking at please ? Can you see the screen shot I attached ? Thank you – OA345 Jun 28 '17 at 20:43

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.