Matthew Ramirez
2018-11-29 01:37:09 UTC
package testngpackage;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class links {
public WebDriver driver;
@BeforeTest
public void openbrowser() {
System.setProperty("webdriver.chrome.driver",
"C:\\Driver\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("https://www.facebook.com");
}
@Test
public void getlinks() {
List<WebElement> links = driver.findElements(By.tagName("a"));
System.out.println("Numero de links = " +links.size());
String[] linktext = new String[links.size()];
int i=0;
for(WebElement e:links) {
linktext[i]= e.getText();
i++;
}
System.out.println(Arrays.toString(linktext));
}
@AfterTest
public void close() {
driver.close();
}
}
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class links {
public WebDriver driver;
@BeforeTest
public void openbrowser() {
System.setProperty("webdriver.chrome.driver",
"C:\\Driver\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("https://www.facebook.com");
}
@Test
public void getlinks() {
List<WebElement> links = driver.findElements(By.tagName("a"));
System.out.println("Numero de links = " +links.size());
String[] linktext = new String[links.size()];
int i=0;
for(WebElement e:links) {
linktext[i]= e.getText();
i++;
}
System.out.println(Arrays.toString(linktext));
}
@AfterTest
public void close() {
driver.close();
}
}
--
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-users+***@googlegroups.com.
To post to this group, send email to selenium-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/413fc1d4-58ae-432f-b6bd-b9ef94739b1c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
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-users+***@googlegroups.com.
To post to this group, send email to selenium-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/413fc1d4-58ae-432f-b6bd-b9ef94739b1c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.