1
votes

I am totally new at any kind of coding and trying to figure out how selenium Webdriver works. I found some videos from one of the online teachers but while I was following that using C# can't seem to find the resolution for the exception below, I tried different selector types from CssSelector to Xpath but wasn't able to figure out what exactly is going wrong. Thank you in Advance.

An unhandled exception of type 'OpenQA.Selenium.InvalidSelectorException' occurred in WebDriver.dll

Additional information: invalid selector: Compound class names not permitted

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Chrome;

namespace WebDriverDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            IWebDriver driver = new ChromeDriver(@"C:\Users\samanat\Documents\Testing\Drivers");
            driver.Url = "http://google.com";
            var searchBox = driver.FindElement(By.Id("lst-ib"));
            searchBox.SendKeys("Global Khulna.com");
            //Searching Global Khulna
            driver.FindElement(By.Name("btnG")).Click();
            //Clicking Search button
            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));

            var imagesLink = driver.FindElements(By.ClassName("q qs"));

            //driver.FindElement(By.TagName("More")).Click();
            //Clicking More
            //driver.FindElement(By.ClassName("q qs")).Click();
            //Clicking Images

        }
    }
}
1

1 Answers

0
votes

within:

var imagesLink = driver.FindElements(By.ClassName("q qs"));//WRONG

When finding a element by ClassName the search string cannot have spaces within it. You will need to find another way to call the element. Most devs use CSS patterns such as:

var imagesLink = driver.FindElement(By.CssSelector("span.q.qs"));

Hope this helps.