This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WebElement txt_label = driver.findElement(By.cssSelector("label[id='uname']")); | |
WebElement txt_label = driver.findElement(withTagName("input").toRightOf(txt_label)); | |
String txt_name = driver.findElement(withTagName("input").toLeftOf(By.id("some_button")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>Group-Name</groupId> | |
<artifactId>Artifact-Name</artifactId> | |
<version>0.0.1-SNAPSHOT</version> | |
<build> | |
<plugins> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-compiler-plugin</artifactId> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io.github.bonigarcia.wdm.WebDriverManager; | |
import org.openqa.selenium.By; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.WebElement; | |
import org.openqa.selenium.chrome.ChromeDriver; | |
import org.openqa.selenium.firefox.FirefoxDriver; | |
import org.testng.annotations.AfterClass; | |
import org.testng.annotations.BeforeClass; | |
import org.testng.annotations.Test; | |
import static org.openqa.selenium.support.locators.RelativeLocator.withTagName; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WebElement heightUserBox = driver.findElement(withTagName("input") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WebElement heightLabel = driver.findElement(By.xpath("//*[@id='app']/section/form/div/div/h1")); | |
// Locate the textbox where username should be inputted | |
WebElement heightUserBox = driver.findElement(withTagName("input") | |
.below(heightLabel)); | |
heightUserBox.sendKeys("user-name"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WebElement heightPasswordBox = driver.findElement(withTagName("input") | |
.below(heightUserBox)); | |
heightPasswordBox.sendKeys("password"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package RelativeLocators; | |
import io.github.bonigarcia.wdm.WebDriverManager; | |
import org.openqa.selenium.By; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.WebElement; | |
import org.openqa.selenium.chrome.ChromeDriver; | |
import org.openqa.selenium.firefox.FirefoxDriver; | |
import org.testng.annotations.AfterClass; | |
import org.testng.annotations.BeforeClass; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul class="list-unstyled"> | |
<!-- ngRepeat: sampletodo in sampleList.sampletodos --><li ng-repeat="sampletodo in sampleList.sampletodos" class="ng-scope"> | |
<input type="checkbox" ng-model="sampletodo.done" name="li1" class="ng-pristine ng-untouched ng-valid"> | |
<span class="done-false">First Item</span> | |
</li><!-- end ngRepeat: sampletodo in sampleList.sampletodos --><li ng-repeat="sampletodo in sampleList.sampletodos" class="ng-scope"> | |
<input type="checkbox" ng-model="sampletodo.done" name="li2" class="ng-pristine ng-untouched ng-valid"> | |
<span class="done-false">Second Item</span> | |
</li><!-- end ngRepeat: sampletodo in sampleList.sampletodos --><li ng-repeat="sampletodo in sampleList.sampletodos" class="ng-scope"> | |
<input type="checkbox" ng-model="sampletodo.done" name="li3" class="ng-pristine ng-untouched ng-valid"> | |
<span class="done-false">Third Item</span> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void test_login_using_relative_locators_1(){ | |
String name = driver.findElement(withTagName("input") | |
.above(By.name("li5")) | |
.below(By.name("li3"))) | |
.getAttribute("name"); | |
assertEquals(name, "li4"); | |
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void test_login_using_relative_locators_2(){ | |
String txt_name = driver.findElement(withTagName("input") | |
.toLeftOf(By.id("addbutton")) | |
.below(By.name("li5"))) | |
.getAttribute("id"); | |
assertEquals(txt_name, "sampletodotext"); | |
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); | |
} |
OlderNewer