Skip to content

Instantly share code, notes, and snippets.

@ShamaUgale
Last active September 28, 2020 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShamaUgale/b5e81d28bb9e32f9b2ecec4b5b8c647b to your computer and use it in GitHub Desktop.
Save ShamaUgale/b5e81d28bb9e32f9b2ecec4b5b8c647b to your computer and use it in GitHub Desktop.
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import static org.openqa.selenium.support.locators.RelativeLocator.withTagName;
public class ApplitoolsBlogsEx {
final static String PROJECT_PATH = System.getProperty("user.dir");
public static void main(String[] args){
System.setProperty("webdriver.chrome.driver", PROJECT_PATH + "/src/main/resources/chromedriver");
ChromeDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://applitools.com/blog/category/advanced-topics/");
WebElement post1 = driver.findElement(By.id("post-22539"));
String post4 = driver.findElement( withTagName("article").below(post1)).getText();
System.out.println(" Below post 1 is : "+ post4);
WebElement post5 = driver.findElement(By.id("post-22033"));
//post 2 is above post 5
String post2 = driver.findElement( withTagName("article").above(post5)).getText();
System.out.println(" Above of post 5 is : "+ post2);
// post 4 is on the left of post 5
post4 = driver.findElement( withTagName("article").toLeftOf(post5)).getText();
System.out.println(" Left of post 5 is : "+ post4);
// post 6 is on the right of post 5
String post6 = driver.findElement( withTagName("article").toRightOf(post5)).getText();
System.out.println(" Right of post 5 is : "+ post6);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment