How to find out all the all links if we enter any keyword in searchbox.

63 views
Skip to first unread message

ritika ritu

unread,
Oct 7, 2015, 6:55:40 AM10/7/15
to Selenium Users
Steps:
1-Enter the keyword in searchbox.
2-Click on searchbox.
3-Results appear related to that search keyword.
4-Now get all the links or Url
5-Click on Pagination
6-Next page reload.
7Now how to get the next page links.

MWQA

unread,
Oct 7, 2015, 6:58:56 AM10/7/15
to Selenium Users
An extremely quick google search brings this up as number 1 result, however, I would presume you have already done this and it doesn't fulfil your needs somehow?  In which case, can you be more specific with your problem?

ritika ritu

unread,
Oct 7, 2015, 7:05:13 AM10/7/15
to seleniu...@googlegroups.com
Here is my code which are extracting the links of first page.import java.util.List;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;


public class Printingall {

public static void main(String[] args) throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
WebElement element = driver.findElement(By.name("q"));
   element.sendKeys("Cheese!\n"); // send also a "\n"
   element.submit();
 //*[@id='rso']//h3/a
   Thread.sleep(3000);
   WebElement myDynamicElement = (new WebDriverWait(driver, 10))
             .until(ExpectedConditions.presenceOfElementLocated(By.id("resultStats")));

   List<WebElement> findElements = driver.findElements(By.xpath("//*[@id='rso']//h3/a"));

   // this are all the links you like to visit
   for (WebElement webElement : findElements)
   {
       System.out.println(webElement.getAttribute("href"));
   }
   
   
   
}
        

}

But what if i have to click on pagination 2 and i need to extract all the links of next page.So My question is 
How to click on pagination and extract all the links of 2nd page..


--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/M6he7F7M_GE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/9c9cf844-3ca3-4149-84d6-00acc0662721%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Ripon Al Wasim

unread,
Oct 7, 2015, 7:08:42 AM10/7/15
to seleniu...@googlegroups.com
Get the xpath or cssSelector of link 2 and click it.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.

To post to this group, send email to seleniu...@googlegroups.com.

ritika ritu

unread,
Oct 7, 2015, 7:10:58 AM10/7/15
to seleniu...@googlegroups.com
What if If i have to extract all the links of 3rd page.

Ripon Al Wasim

unread,
Oct 7, 2015, 7:11:42 AM10/7/15
to seleniu...@googlegroups.com
Same to do by navigating to the 3rd page.

Mark Collin

unread,
Oct 7, 2015, 10:15:19 AM10/7/15
to Selenium Users
You do realise that Google will blacklist you if they realise what you are doing.  It's against their terms of service.

If you want to do scrape links you are better off using a bot to scrape sites for you than using Selenium
To unsubscribe from this group and all its topics, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.

ritika ritu

unread,
Oct 8, 2015, 12:55:35 AM10/8/15
to seleniu...@googlegroups.com
Thanks For Your Suggestion.

To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/M6he7F7M_GE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/4de7b9c8-953f-4c65-a291-170fd7d63860%40googlegroups.com.

Rajni Soni

unread,
Oct 8, 2015, 4:51:26 AM10/8/15
to Selenium Users
Can any body help me with this:
I am using selenium iDE... recorded the steps..but not able to execute them.
As I click on the button to execute...nothing happens..
Reply all
Reply to author
Forward
0 new messages