0

i am learning Selenium i need some help. okay i was working with This website . here is use case :

  1. Enter Text in search bar (Done)
  2. Press Search Button. (Not Done)

I have tried with className to click button but it is not working

//then this method to search 

void invokeChrome(){
    try{
        System.setProperty("webdriver.chrome.driver", "D:\\software testing\\chromedriver.exe");
        web = new ChromeDriver();
        web.manage().deleteAllCookies();
        web.manage().window().maximize();
        web.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        web.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
        web.get("https://www.coursera.org");
    }catch(Exception e)
    {
        System.out.println(e.getMessage());
    }
}

I am using Chromedrive 74 and selenium : 3.9.0 release

Ed Bangga
  • 12,879
  • 4
  • 16
  • 30
  • Did you got `compound class` exception when ran the test? – supputuri Jul 05 '19 at 04:08
  • yes : org.openqa.selenium.InvalidSelectorException: invalid selector: Compound class names not permitted – Awais Arshad Jul 05 '19 at 04:40
  • @supputuri sometimes i get this exception as well. i am sorry i am new to selenium , if asking lame questions : `org.openqa.selenium.WebDriverException: java.net.SocketTimeoutException: timeout` – Awais Arshad Jul 05 '19 at 04:43

1 Answers1

0

nostyle mobile-magnifier is not a single class, it has 2 classes so you are getting compound class exception when try with By.className. So change that line as shown below using xpath.

Xpath:

 web.findElement(By.xpath("//button[@aria-label='Enter Search'] [2]")).click();
supputuri
  • 13,644
  • 2
  • 21
  • 39
  • Try this out and let me know still you get the exceptions. – supputuri Jul 05 '19 at 04:45
  • yes i tried both of them , it is giving `org.openqa.selenium.WebDriverException: java.net.SocketTimeoutException: timeout` – Awais Arshad Jul 05 '19 at 04:47
  • after writing text inside search bar , it stuck there and give `timeout` exception – Awais Arshad Jul 05 '19 at 04:48
  • Got it. There are 2 elements that match with xpath and the first one is hidden so we are not able to click on it. Try with the updated answer it's working for me in python. – supputuri Jul 05 '19 at 05:05
  • Yes it is working thank you so much, can you recommend me which language is trendy for selenium testing. java or python . also can you recommend me some good links to learn basics to advance . i am aiming to learn all stuff related to selenium within 2 days , also is this possible ? – Awais Arshad Jul 05 '19 at 05:12
  • Personally I prefer python, but always it's a choice between the languages based on the language used by your dev team and team comfort. You can get the important and regular actions in 2 days but not everything related to selenium, which you will get with practice/experience. All the best thought!! cheers. – supputuri Jul 05 '19 at 05:16
  • Thank you very much for your help. i really appreciate that . thanks again and have a good day . – Awais Arshad Jul 05 '19 at 05:19
  • can you please have a look on this problem : [This Question ](https://stackoverflow.com/questions/56908435/java-selenium-cant-login-gmail) – Awais Arshad Jul 06 '19 at 04:54