How to find the auto suggestion on google search with Xpath2019 Community Moderator ElectionHow to compile a java application which uses Google webdriver from comand line without antxpath - how to find infoThe selenium webdriver always pickup the second result from google search suggestionParameters is passing default value in TestNGPlease suggest xpath to print “Vor 16 Stunden”xpath for a input search box auto suggestion list items as like in googleNoSuchElement Exception (selenium)Get sub-item's XPath using Selenium - JavaSelenium: org.openqa.selenium.NoSuchWindowException: Currently focused window has been closedHow to retrieve Yahoo search auto suggestions through selenium and xpath

Have researchers managed to "reverse time"? If so, what does that mean for physics?

Gravity magic - How does it work?

Why did it take so long to abandon sail after steamships were demonstrated?

How to write cleanly even if my character uses expletive language?

What is the significance behind "40 days" that often appears in the Bible?

Instead of Universal Basic Income, why not Universal Basic NEEDS?

Unexpected result from ArcLength

How can I track script which gives me "command not found" right after the login?

Property of summation

(Calculus) Derivative Thinking Question

What do Xenomorphs eat in the Alien series?

What approach do we need to follow for projects without a test environment?

Happy pi day, everyone!

Are there verbs that are neither telic, or atelic?

It's a yearly task, alright

Time travel from stationary position?

Python if-else code style for reduced code for rounding floats

Official degrees of earth’s rotation per day

Welcoming 2019 Pi day: How to draw the letter π?

Use of undefined constant bloginfo

What's the meaning of “spike” in the context of “adrenaline spike”?

SOQL: Populate a Literal List in WHERE IN Clause

Why do passenger jet manufacturers design their planes with stall prevention systems?

Look at your watch and tell me what time is it. vs Look at your watch and tell me what time it is



How to find the auto suggestion on google search with Xpath



2019 Community Moderator ElectionHow to compile a java application which uses Google webdriver from comand line without antxpath - how to find infoThe selenium webdriver always pickup the second result from google search suggestionParameters is passing default value in TestNGPlease suggest xpath to print “Vor 16 Stunden”xpath for a input search box auto suggestion list items as like in googleNoSuchElement Exception (selenium)Get sub-item's XPath using Selenium - JavaSelenium: org.openqa.selenium.NoSuchWindowException: Currently focused window has been closedHow to retrieve Yahoo search auto suggestions through selenium and xpath










0















With Selenium webdriver, I am trying search 'Selenium' in google search box, which provides auto suggestions of several texts. Then I am trying to click one particular text from auto suggestions list. It seems though, my Xpath is not working.



Below is the code I wrote:



package com.initial.selenium;
import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class GoogleSearch {

public static void main(String[] args)
System.setProperty("webdriver.chrome.driver",
"C:\Users\Shahid\eclipse-
workspace\InitialSeleniumProject\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.google.com");
driver.findElement(By.xpath("//*[@name='q']")).sendKeys("selenium");
List < WebElement >

mylist=driver.findElements(By.xpath("//ul[@role='listbox']//li/descendant::div[@class='sbl1']/span"));
System.out.println(mylist.size());
for (int i = 0; i < mylist.size(); i++)

System.out.println(mylist.get(i).getText());
if (mylist.get(i).getText().contains("Selenium Benefits"))
mylist.get(i).click();
break;














share|improve this question



















  • 1





    what does not working mean?

    – QHarr
    Mar 6 at 20:05












  • The script results 0

    – Shahid Islam
    Mar 7 at 2:14











  • Did you try webdriverwait?

    – Kamal
    Mar 7 at 5:15











  • @ShahidIslam use this xpath - //ul[@class='erkvQe']//li and fetch text from it. it will return span text.

    – Dhru 'soni
    Mar 7 at 7:29











  • @Dhru 'Soni: thank you. That has done the trick. I still do not understand why my xpath was not working. If you can, please, indicate any problem with my xpath, I would really appreciate it.

    – Shahid Islam
    Mar 7 at 16:55















0















With Selenium webdriver, I am trying search 'Selenium' in google search box, which provides auto suggestions of several texts. Then I am trying to click one particular text from auto suggestions list. It seems though, my Xpath is not working.



Below is the code I wrote:



package com.initial.selenium;
import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class GoogleSearch {

public static void main(String[] args)
System.setProperty("webdriver.chrome.driver",
"C:\Users\Shahid\eclipse-
workspace\InitialSeleniumProject\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.google.com");
driver.findElement(By.xpath("//*[@name='q']")).sendKeys("selenium");
List < WebElement >

mylist=driver.findElements(By.xpath("//ul[@role='listbox']//li/descendant::div[@class='sbl1']/span"));
System.out.println(mylist.size());
for (int i = 0; i < mylist.size(); i++)

System.out.println(mylist.get(i).getText());
if (mylist.get(i).getText().contains("Selenium Benefits"))
mylist.get(i).click();
break;














share|improve this question



















  • 1





    what does not working mean?

    – QHarr
    Mar 6 at 20:05












  • The script results 0

    – Shahid Islam
    Mar 7 at 2:14











  • Did you try webdriverwait?

    – Kamal
    Mar 7 at 5:15











  • @ShahidIslam use this xpath - //ul[@class='erkvQe']//li and fetch text from it. it will return span text.

    – Dhru 'soni
    Mar 7 at 7:29











  • @Dhru 'Soni: thank you. That has done the trick. I still do not understand why my xpath was not working. If you can, please, indicate any problem with my xpath, I would really appreciate it.

    – Shahid Islam
    Mar 7 at 16:55













0












0








0








With Selenium webdriver, I am trying search 'Selenium' in google search box, which provides auto suggestions of several texts. Then I am trying to click one particular text from auto suggestions list. It seems though, my Xpath is not working.



Below is the code I wrote:



package com.initial.selenium;
import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class GoogleSearch {

public static void main(String[] args)
System.setProperty("webdriver.chrome.driver",
"C:\Users\Shahid\eclipse-
workspace\InitialSeleniumProject\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.google.com");
driver.findElement(By.xpath("//*[@name='q']")).sendKeys("selenium");
List < WebElement >

mylist=driver.findElements(By.xpath("//ul[@role='listbox']//li/descendant::div[@class='sbl1']/span"));
System.out.println(mylist.size());
for (int i = 0; i < mylist.size(); i++)

System.out.println(mylist.get(i).getText());
if (mylist.get(i).getText().contains("Selenium Benefits"))
mylist.get(i).click();
break;














share|improve this question
















With Selenium webdriver, I am trying search 'Selenium' in google search box, which provides auto suggestions of several texts. Then I am trying to click one particular text from auto suggestions list. It seems though, my Xpath is not working.



Below is the code I wrote:



package com.initial.selenium;
import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class GoogleSearch {

public static void main(String[] args)
System.setProperty("webdriver.chrome.driver",
"C:\Users\Shahid\eclipse-
workspace\InitialSeleniumProject\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.google.com");
driver.findElement(By.xpath("//*[@name='q']")).sendKeys("selenium");
List < WebElement >

mylist=driver.findElements(By.xpath("//ul[@role='listbox']//li/descendant::div[@class='sbl1']/span"));
System.out.println(mylist.size());
for (int i = 0; i < mylist.size(); i++)

System.out.println(mylist.get(i).getText());
if (mylist.get(i).getText().contains("Selenium Benefits"))
mylist.get(i).click();
break;











java selenium webdriver






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 7 at 2:18









Vega

13.5k113860




13.5k113860










asked Mar 6 at 19:51









Shahid IslamShahid Islam

62




62







  • 1





    what does not working mean?

    – QHarr
    Mar 6 at 20:05












  • The script results 0

    – Shahid Islam
    Mar 7 at 2:14











  • Did you try webdriverwait?

    – Kamal
    Mar 7 at 5:15











  • @ShahidIslam use this xpath - //ul[@class='erkvQe']//li and fetch text from it. it will return span text.

    – Dhru 'soni
    Mar 7 at 7:29











  • @Dhru 'Soni: thank you. That has done the trick. I still do not understand why my xpath was not working. If you can, please, indicate any problem with my xpath, I would really appreciate it.

    – Shahid Islam
    Mar 7 at 16:55












  • 1





    what does not working mean?

    – QHarr
    Mar 6 at 20:05












  • The script results 0

    – Shahid Islam
    Mar 7 at 2:14











  • Did you try webdriverwait?

    – Kamal
    Mar 7 at 5:15











  • @ShahidIslam use this xpath - //ul[@class='erkvQe']//li and fetch text from it. it will return span text.

    – Dhru 'soni
    Mar 7 at 7:29











  • @Dhru 'Soni: thank you. That has done the trick. I still do not understand why my xpath was not working. If you can, please, indicate any problem with my xpath, I would really appreciate it.

    – Shahid Islam
    Mar 7 at 16:55







1




1





what does not working mean?

– QHarr
Mar 6 at 20:05






what does not working mean?

– QHarr
Mar 6 at 20:05














The script results 0

– Shahid Islam
Mar 7 at 2:14





The script results 0

– Shahid Islam
Mar 7 at 2:14













Did you try webdriverwait?

– Kamal
Mar 7 at 5:15





Did you try webdriverwait?

– Kamal
Mar 7 at 5:15













@ShahidIslam use this xpath - //ul[@class='erkvQe']//li and fetch text from it. it will return span text.

– Dhru 'soni
Mar 7 at 7:29





@ShahidIslam use this xpath - //ul[@class='erkvQe']//li and fetch text from it. it will return span text.

– Dhru 'soni
Mar 7 at 7:29













@Dhru 'Soni: thank you. That has done the trick. I still do not understand why my xpath was not working. If you can, please, indicate any problem with my xpath, I would really appreciate it.

– Shahid Islam
Mar 7 at 16:55





@Dhru 'Soni: thank you. That has done the trick. I still do not understand why my xpath was not working. If you can, please, indicate any problem with my xpath, I would really appreciate it.

– Shahid Islam
Mar 7 at 16:55












1 Answer
1






active

oldest

votes


















0














In this case, the error you're getting (a null result) is because the ul element you're targeting doesn't contain any elements.



Image displaying that the target ul doesn't contain any children



So, in this case, you're going to change your target. Instead of doing:



ul[@role='listbox']


Do



li[@role='presentation']


And that will result in



//li[@role='presentation']/descendant::div[@class='sbl1']/span


Which returns the span you're trying to get.






share|improve this answer























  • With this xpath, the script results 1

    – Shahid Islam
    Mar 7 at 2:15











  • I still cannot find what is wrong with my xpath. However, none of the suggested xpath including mine are provide intended result. I would appreciate any other help

    – Shahid Islam
    Mar 7 at 6:15










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55031150%2fhow-to-find-the-auto-suggestion-on-google-search-with-xpath%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














In this case, the error you're getting (a null result) is because the ul element you're targeting doesn't contain any elements.



Image displaying that the target ul doesn't contain any children



So, in this case, you're going to change your target. Instead of doing:



ul[@role='listbox']


Do



li[@role='presentation']


And that will result in



//li[@role='presentation']/descendant::div[@class='sbl1']/span


Which returns the span you're trying to get.






share|improve this answer























  • With this xpath, the script results 1

    – Shahid Islam
    Mar 7 at 2:15











  • I still cannot find what is wrong with my xpath. However, none of the suggested xpath including mine are provide intended result. I would appreciate any other help

    – Shahid Islam
    Mar 7 at 6:15















0














In this case, the error you're getting (a null result) is because the ul element you're targeting doesn't contain any elements.



Image displaying that the target ul doesn't contain any children



So, in this case, you're going to change your target. Instead of doing:



ul[@role='listbox']


Do



li[@role='presentation']


And that will result in



//li[@role='presentation']/descendant::div[@class='sbl1']/span


Which returns the span you're trying to get.






share|improve this answer























  • With this xpath, the script results 1

    – Shahid Islam
    Mar 7 at 2:15











  • I still cannot find what is wrong with my xpath. However, none of the suggested xpath including mine are provide intended result. I would appreciate any other help

    – Shahid Islam
    Mar 7 at 6:15













0












0








0







In this case, the error you're getting (a null result) is because the ul element you're targeting doesn't contain any elements.



Image displaying that the target ul doesn't contain any children



So, in this case, you're going to change your target. Instead of doing:



ul[@role='listbox']


Do



li[@role='presentation']


And that will result in



//li[@role='presentation']/descendant::div[@class='sbl1']/span


Which returns the span you're trying to get.






share|improve this answer













In this case, the error you're getting (a null result) is because the ul element you're targeting doesn't contain any elements.



Image displaying that the target ul doesn't contain any children



So, in this case, you're going to change your target. Instead of doing:



ul[@role='listbox']


Do



li[@role='presentation']


And that will result in



//li[@role='presentation']/descendant::div[@class='sbl1']/span


Which returns the span you're trying to get.







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 6 at 20:17









SquirrelSquirrel

367615




367615












  • With this xpath, the script results 1

    – Shahid Islam
    Mar 7 at 2:15











  • I still cannot find what is wrong with my xpath. However, none of the suggested xpath including mine are provide intended result. I would appreciate any other help

    – Shahid Islam
    Mar 7 at 6:15

















  • With this xpath, the script results 1

    – Shahid Islam
    Mar 7 at 2:15











  • I still cannot find what is wrong with my xpath. However, none of the suggested xpath including mine are provide intended result. I would appreciate any other help

    – Shahid Islam
    Mar 7 at 6:15
















With this xpath, the script results 1

– Shahid Islam
Mar 7 at 2:15





With this xpath, the script results 1

– Shahid Islam
Mar 7 at 2:15













I still cannot find what is wrong with my xpath. However, none of the suggested xpath including mine are provide intended result. I would appreciate any other help

– Shahid Islam
Mar 7 at 6:15





I still cannot find what is wrong with my xpath. However, none of the suggested xpath including mine are provide intended result. I would appreciate any other help

– Shahid Islam
Mar 7 at 6:15



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55031150%2fhow-to-find-the-auto-suggestion-on-google-search-with-xpath%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

1928 у кіно

Захаров Федір Захарович

Ель Греко