Advertisement
Guest User

Untitled

a guest
Jan 12th, 2021
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. package org.example.untitled;
  2.  
  3. import org.junit.jupiter.api.Test;
  4. import org.openqa.selenium.By;
  5. import org.openqa.selenium.WebDriver;
  6. import org.openqa.selenium.WebElement;
  7. import org.openqa.selenium.firefox.FirefoxDriver;
  8. import org.openqa.selenium.firefox.FirefoxOptions;
  9. import org.openqa.selenium.support.ui.ExpectedConditions;
  10. import org.openqa.selenium.support.ui.WebDriverWait;
  11.  
  12. import javax.swing.*;
  13. import java.io.ByteArrayInputStream;
  14. import java.io.FileInputStream;
  15. import java.io.InputStream;
  16. import java.util.List;
  17. import java.util.Scanner;
  18. import java.util.concurrent.TimeUnit;
  19. import java.util.stream.Collectors;
  20.  
  21. import static jdk.internal.org.jline.utils.AttributedStringBuilder.append;
  22. import static sun.net.www.protocol.http.HttpURLConnection.userAgent;
  23.  
  24.  
  25. public class MainPageTest {
  26.  
  27.  
  28. @Test
  29. public void openPage() {
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37. WebDriver driver;
  38. System.setProperty("webdriver.gecko.driver", "C:\\Users\\Kirill\\Desktop\\geckodriver.exe");
  39. FirefoxOptions options = new FirefoxOptions();
  40. options.addPreference("general.useragent.override",userAgent);
  41. String userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36 OPR/60.0.3255.170";
  42. driver = new FirefoxDriver();
  43. driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
  44. driver.get("https://www.instagram.com/");
  45. driver.findElement(By.xpath("//*[@id=\"loginForm\"]/div/div[1]/div/label/input")).sendKeys("MY LOGIN"); // LOG
  46. driver.findElement(By.xpath("//*[@id=\"loginForm\"]/div/div[2]/div/label/input")).sendKeys("PASSWORD"); //PASS
  47. driver.manage().timeouts().implicitlyWait(29, TimeUnit.SECONDS);
  48. driver.findElement(By.xpath("//*[@id=\"loginForm\"]/div/div[3]")).click();
  49. driver.findElement(By.xpath("//*[@id=\"react-root\"]/section/main/div/div/div/div/button")).click();
  50. driver.findElement(By.cssSelector("button.aOOlW:nth-child(2)")).click();
  51. String hashtag = null;
  52. driver.get("https://www.instagram.com/explore/tags/"+hashtag);
  53. List<WebElement> all_links = driver.findElements(By.xpath("//a[.//p]"));
  54. System.out.println(driver.findElements(By.xpath("//a[.//p]")).stream().map(element->element.getText()).collect(Collectors.toList()));
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement