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

Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved