Please help me while creating yahoo assignment | Selenium Forum
M
Posted on 02/10/2015
I have to enlist all the news which are present on yahoo navigation bar

http://yahoo.co.in

Part 1
1.Navigate to the URL
2.Observe that currently 5 news are displayed on Navigation
3.print 5 news
4.Navigate to the next set of 5 news
5. So on
6.Same script have to run if the news are updated by next day


Issue:On navigation if currently xyz news is present at position 1,tomorow its position will change due to upation in news
so i am unable automate the script with constant locator

please help me to solve this problem

M
Replied on 02/10/2015

its will be hard what is current locater you are using?


M
Replied on 04/10/2015

I am using css selector ,currently i want to print all the news text which is present on carousels in the form of set of 5 news

I have tried multiple combinations but unable to print all the news

Currently with help li[class*='Carousel-Item Grid-U-1-5'] path I am able to print on only first set of five news

Once i click on navigation button for next set of 5 news am unable to print it

How should I solve this problem



import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class yahoo {

public static void main(String[] args) throws InterruptedException {



WebDriver driver = new FirefoxDriver();
driver.get("https://in.yahoo.com");
Thread.sleep(1000);
driver.findElement(By.xpath("//button[@class='js-today-playpause PlayPauseBtn ButtonNaked']")).click();
List<WebElement> news = driver.findElements(By.cssSelector("li[class*='Carousel-Item Grid-U-1-5']"));
int newnews=news.size();
System.out.println(newnews);
for(int i=5;i<news.size();i=+5)

{
for(int j=0;j<i;j++)
{
System.out.println(news.get(j).getText());
}

Thread.sleep(7000);
driver.findElement(By.xpath("//button[@title='Next'] ")).click();

}

// }
//
}
}


M
Replied on 05/10/2015

there you go

[quote:3cehy1wt]package com.soapuitutorial.propertie;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class yahoo {

public static void main(String[] args) throws InterruptedException {

WebDriver driver = new FirefoxDriver();
driver.get("https://in.yahoo.com");
Thread.sleep(1000);
driver.findElement(
By.xpath("//button[@class='js-today-playpause PlayPauseBtn ButtonNaked']"))
.click();
List<WebElement> news = driver.findElements(By
.cssSelector("li[class*='Carousel-Item Grid-U-1-5']"));
int newnews = news.size();
System.out.println(newnews);

for (int j = 0; j < news.size(); j++) {
System.out.println(news.get(j).getText());
}

Thread.sleep(7000);

driver.findElement(By.xpath("//button[@title='Next'] ")).click();

news = driver.findElements(By
.cssSelector("li[class*='Carousel-Item Grid-U-1-5']"));
newnews = news.size();
System.out.println(newnews);

for (int j = 0; j < news.size(); j++) {
System.out.println(news.get(j).getText());
}

driver.findElement(By.xpath("//button[@title='Next'] ")).click();

news = driver.findElements(By
.cssSelector("li[class*='Carousel-Item Grid-U-1-5']"));
newnews = news.size();
System.out.println(newnews);

for (int j = 0; j < news.size(); j++) {
System.out.println(news.get(j).getText());
}
}
}[/quote:3cehy1wt]


M
Replied on 05/10/2015

Thanks for the help

Is there any way to optimize this logic

Because currently there is individual loop for each set of news (ex.if there are 55 news so i have to write 11 for loops)


can you please help to provide optimum solution


M
Replied on 05/10/2015

I'm tied up with my other project, so i can't help you, sorry. I'm sure you can find optimum solution. basically you have to put it in a loop.