How to use presenceOfNestedElementLocatedBy method of org.openqa.selenium.support.ui.ExpectedConditions class

Best Selenium code snippet using org.openqa.selenium.support.ui.ExpectedConditions.presenceOfNestedElementLocatedBy

Source:ScriptingScenarioSampleTest.java Github

copy

Full Screen

...13import static org.openqa.selenium.By.linkText;14import static org.openqa.selenium.By.xpath;15import static org.openqa.selenium.support.ui.ExpectedConditions.elementToBeClickable;16import static org.openqa.selenium.support.ui.ExpectedConditions.numberOfElementsToBeMoreThan;17import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfNestedElementLocatedBy;18import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOf;19public class ScriptingScenarioSampleTest extends AbstractSeleniumBaseTest {20 WebDriverWait wait;21 Actions actions;22 @Test23 public void scriptingTest() {24 System.out.println("Browser Name property -> " + System.getProperty("browser.name"));25 System.out.println("Site Url property -> " + System.getProperty("site.url"));26 wait = new WebDriverWait(driver, 5);27 actions = new Actions(driver);28 /​/​ 1. Открыть Яндекс маркет29 driver.navigate().to("https:/​/​market.yandex.ru/​");30 /​/​ 2. Выбрать категорию "Компьютеры"31 wait.until(elementToBeClickable(xpath("/​/​span[contains(text(),'Компьютеры')]"))).click();32 /​/​ 3. Выбрать подкатегорию "Ноутбуки"33 wait.until(elementToBeClickable(linkText("Ноутбуки"))).click();34 List<String> selectedProductNames = new ArrayList<>();35 List<WebElement> products = wait.until(numberOfElementsToBeMoreThan(cssSelector("[data-autotest-id='product-snippet']"), 3));36 /​/​ 4. Добавить первый товар к сравнению37 selectedProductNames.add(addProductToCompare(products, 0));38 /​/​ 5. добавить второй товар к сравнению39 selectedProductNames.add(addProductToCompare(products, 1));40 /​/​ 6. Нажать на кнопку сравнить товары41 wait.until(elementToBeClickable(xpath("/​/​a/​span[text()='Сравнить']"))).click();42 /​/​7. Проверить, что выбранные товары были добавлены к сравнению43 List<WebElement> comparedProducts = wait.until(numberOfElementsToBeMoreThan(cssSelector("[data-tid='412661c'] a.cia-cs"), 1));44 List<String> comparedProductNames = comparedProducts.stream().map(WebElement::getText).collect(Collectors.toList());45 assertThat(comparedProductNames, containsInAnyOrder(selectedProductNames.toArray(new String[selectedProductNames.size()])));46 }47 private String addProductToCompare(List<WebElement> products, int productNumber) {48 WebElement addToCompare = wait.until(presenceOfNestedElementLocatedBy(products.get(productNumber),49 xpath("./​/​div[contains(@aria-label, 'сравнению')]")));50 actions51 .moveToElement(addToCompare)52 .click()53 .build()54 .perform();55 return wait.until(visibilityOf(products.get(productNumber)56 .findElement(xpath("./​/​div/​/​child::h3[@data-zone-name='title']")))).getText().trim();57 }58}...

Full Screen

Full Screen

Source:BaseFunc.java Github

copy

Full Screen

...44 return parent.findElements(child);45 }46 public String getText(WebElement parent, By child) {47 LOGGER.info("Getting text for child element by locator");48 return wait.until(ExpectedConditions.presenceOfNestedElementLocatedBy(parent, child)).getText();49 }50 public String getText(By parent, By child) {51 return wait.until(ExpectedConditions.presenceOfNestedElementLocatedBy(parent, child)).getText();52 }53 public String getText(By locator) {54 LOGGER.info("Getting text from web element");55 return wait.until(ExpectedConditions.visibilityOfElementLocated(locator)).getText();56 }57 public void closeBrowser() {58 LOGGER.info("");59 if (driver != null) {60 driver.close();61 }62 }63 public WebElement findElement(By locator) {64 LOGGER.info("Getting element by locator: " + locator);65 return wait.until(ExpectedConditions.visibilityOfElementLocated(locator));...

Full Screen

Full Screen

Source:YandexMarketSeleniumActionBuilderTest.java Github

copy

Full Screen

...6import static org.openqa.selenium.By.xpath;7import static org.openqa.selenium.support.ui.ExpectedConditions.elementToBeClickable;8import static org.openqa.selenium.support.ui.ExpectedConditions.numberOfElementsToBe;9import static org.openqa.selenium.support.ui.ExpectedConditions.numberOfElementsToBeMoreThan;10import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfNestedElementLocatedBy;11import java.util.ArrayList;12import java.util.List;13import java.util.stream.Collectors;14import org.openqa.selenium.WebElement;15import org.openqa.selenium.interactions.Actions;16import org.openqa.selenium.support.ui.WebDriverWait;17import org.testng.annotations.BeforeMethod;18import org.testng.annotations.Test;19public class YandexMarketSeleniumActionBuilderTest extends AbstractSeleniumBaseTest {20 private WebDriverWait wait;21 @BeforeMethod22 @Override23 public void setUp() {24 super.setUp();25 driver.navigate().to(URL);26 wait = new WebDriverWait(driver, 10);27 driver.manage().window().maximize();28 }29 @Test30 public void addProductToCompareListTest() {31 wait.until(elementToBeClickable(xpath("/​/​span[text() = 'Электроника']"))).click();32 wait.until(elementToBeClickable(linkText("Смартфоны"))).click();33 var productCards =34 wait.until(numberOfElementsToBeMoreThan(cssSelector("[data-autotest-id='product-snippet']"), 2));35 var productCard = productCards.get(0);36 var productCardTitle = productCard.findElement(cssSelector("h3[data-zone-name='title'] span"))37 .getText();38 var addToCompareButton = wait.until(39 presenceOfNestedElementLocatedBy(productCard, xpath("/​/​div[contains(@aria-label, 'сравнению')]")));40 Actions actions = new Actions(driver);41 actions42 .moveToElement(addToCompareButton)43 .click()44 .perform();45 List<String> expectedTitles = new ArrayList<>();46 expectedTitles.add(productCardTitle);47 productCard = productCards.get(1);48 productCardTitle = productCard.findElement(cssSelector("h3[data-zone-name='title'] span"))49 .getText();50 addToCompareButton = wait.until(51 presenceOfNestedElementLocatedBy(productCard, xpath("/​/​div[contains(@aria-label, 'сравнению')]")));52 actions53 .moveToElement(addToCompareButton)54 .click()55 .perform();56 expectedTitles.add(productCardTitle);57 wait.until(elementToBeClickable(xpath("/​/​a/​span[text()='Сравнить']"))).click();58 var actualWebElements = wait.until(numberOfElementsToBe(className("_27nuSZ19h7"), expectedTitles.size()));59 var actualTitles = actualWebElements60 .stream()61 .map(WebElement::getText)62 .collect(Collectors.toList());63 assertThat(actualTitles)64 .as("Incorrect products in compare list")65 .containsExactlyInAnyOrderElementsOf(expectedTitles);...

Full Screen

Full Screen

Source:YandexMarketCatalogItemPage.java Github

copy

Full Screen

...7import static org.openqa.selenium.By.cssSelector;8import static org.openqa.selenium.By.xpath;9import static org.openqa.selenium.support.ui.ExpectedConditions.elementToBeClickable;10import static org.openqa.selenium.support.ui.ExpectedConditions.numberOfElementsToBeMoreThan;11import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfNestedElementLocatedBy;12import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOf;13public class YandexMarketCatalogItemPage {14 private WebDriver driver;15 private WebDriverWait wait;16 public YandexMarketCatalogItemPage(WebDriver driver) {17 this.driver = driver;18 this.wait = new WebDriverWait(driver, 10);19 }20 public String addProductToCompare(int index) {21 List<WebElement> products = wait.until(numberOfElementsToBeMoreThan(cssSelector("[data-autotest-id='product-snippet']"), 3));22 return addProductToCompare(products, index - 1);23 }24 public YandexMarketCompareProductPage clickCompareButton() {25 wait.until(elementToBeClickable(xpath("/​/​a/​span[text()='Сравнить']"))).click();26 return new YandexMarketCompareProductPage(driver);27 }28 private String addProductToCompare(List<WebElement> products, int productNumber) {29 WebElement addToCompare = wait.until(presenceOfNestedElementLocatedBy(products.get(productNumber),30 xpath("./​/​div[contains(@aria-label, 'сравнению')]")));31 new Actions(driver)32 .moveToElement(addToCompare)33 .click()34 .build()35 .perform();36 return wait.until(visibilityOf(products.get(productNumber)37 .findElement(xpath("./​/​div/​/​child::h3[@data-zone-name='title']")))).getText().trim();38 }39}...

Full Screen

Full Screen

Source:YandexMarketCategoryProductPage.java Github

copy

Full Screen

...7import java.util.List;8import static org.openqa.selenium.By.xpath;9import static org.openqa.selenium.support.ui.ExpectedConditions.elementToBeClickable;10import static org.openqa.selenium.support.ui.ExpectedConditions.numberOfElementsToBeMoreThan;11import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfNestedElementLocatedBy;12import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOf;13public class YandexMarketCategoryProductPage {14 private static WebDriver driver;15 public static void init(WebDriver webDriver) {16 driver = webDriver;17 }18 public static String addProductToCompare(int productNumber) {19 List<WebElement> productCards = new WebDriverWait(driver, 5).until(numberOfElementsToBeMoreThan(By.cssSelector("[data-autotest-id='product-snippet']"), 3));20 WebElement productCard = productCards.get(productNumber - 1);21 WebElement addToCompare = new WebDriverWait(driver, 5).until(presenceOfNestedElementLocatedBy(productCard,22 xpath("./​/​div[contains(@aria-label, 'сравнению')]")));23 new Actions(driver)24 .moveToElement(addToCompare)25 .click()26 .build()27 .perform();28 return new WebDriverWait(driver, 5).until(visibilityOf(productCard.findElement(xpath("./​/​div/​/​child::h3[@data-zone-name='title']")))).getText().trim();29 }30 public static void clickCompareButton() {31 new WebDriverWait(driver, 5).until(elementToBeClickable(By.xpath("/​/​a/​span[text()='Сравнить']"))).click();32 }33}...

Full Screen

Full Screen

Source:YandexMarketProductsPage.java Github

copy

Full Screen

...6import org.openqa.selenium.support.ui.ExpectedConditions;7import org.openqa.selenium.support.ui.WebDriverWait;8import java.util.List;9import static org.openqa.selenium.By.xpath;10import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfNestedElementLocatedBy;11import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOf;12public class YandexMarketProductsPage extends AbstractYandexMarketPage {13 @FindBy(css = "[data-autotest-id='product-snippet']")14 private List<WebElement> productList;15 @FindBy(xpath = "/​/​a/​span[text()='Сравнить']")16 private WebElement compareButton;17 public YandexMarketProductsPage(WebDriver driver) {18 super(driver);19 }20 public String addProductToCompare(int productNumber) {21 WebDriverWait wait = new WebDriverWait(driver, 5);22 WebElement addToCompare = wait.until(presenceOfNestedElementLocatedBy(productList.get(productNumber),23 xpath("./​/​div[contains(@aria-label, 'сравнению')]")));24 new Actions(driver)25 .moveToElement(addToCompare)26 .click()27 .build()28 .perform();29 return wait.until(visibilityOf(productList.get(productNumber)30 .findElement(xpath("./​/​div/​/​child::h3[@data-zone-name='title']")))).getText().trim();31 }32 public void clickCompareButton() {33 new WebDriverWait(driver, 5).until(ExpectedConditions.elementToBeClickable(compareButton)).click();34 }35}...

Full Screen

Full Screen

Source:ProductComponent.java Github

copy

Full Screen

...3import org.openqa.selenium.WebElement;4import org.openqa.selenium.interactions.Actions;5import org.openqa.selenium.support.ui.WebDriverWait;6import static org.openqa.selenium.By.xpath;7import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfNestedElementLocatedBy;8import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOf;9public class ProductComponent {10 private WebDriver driver;11 private WebDriverWait wait;12 private Actions actions;13 private WebElement rootElement;14 public ProductComponent(WebDriver driver, WebElement rootElement) {15 this.driver = driver;16 this.rootElement = rootElement;17 wait = new WebDriverWait(driver, 10);18 actions = new Actions(driver);19 }20 public ProductComponent clickAddToCompareButton() {21 WebElement addToCompare = wait.until(presenceOfNestedElementLocatedBy(rootElement,22 xpath("./​/​div[contains(@aria-label, 'сравнению')]")));23 new Actions(driver)24 .moveToElement(addToCompare)25 .click()26 .build()27 .perform();28 return this;29 }30 public String getTitle() {31 return wait.until(visibilityOf(rootElement32 .findElement(xpath("./​/​div/​/​child::h3[@data-zone-name='title']")))).getText().trim();33 }34}...

Full Screen

Full Screen

Source:ParentPage.java Github

copy

Full Screen

...23 }24 protected String getNestedElementAttribute(WebElement parent, By selector, String attribute) {25 return wait.until(26 ExpectedConditions.27 presenceOfNestedElementLocatedBy(parent, selector)28 ).getAttribute(attribute);29 }30 protected String getNestedElementText(WebElement parent, By nestedElementLocator) {31 return wait.until(32 ExpectedConditions.33 presenceOfNestedElementLocatedBy(parent, nestedElementLocator)34 ).getText();35 }36}...

Full Screen

Full Screen

presenceOfNestedElementLocatedBy

Using AI Code Generation

copy

Full Screen

1public class Test {2 public static WebElement getWebElement() {3 return null;4 }5}6public class Test1 {7 public static WebElement getWebElement() {8 return null;9 }10}11public class Test2 {12 public static WebElement getWebElement() {13 return null;14 }15}16public class Test3 {17 public static WebElement getWebElement() {18 return null;19 }20}21public class Test4 {22 public static WebElement getWebElement() {23 return null;24 }25}26public class Test5 {27 public static WebElement getWebElement() {28 return null;29 }30}31public class Test6 {32 public static WebElement getWebElement() {33 return null;34 }35}36public class Test7 {37 public static WebElement getWebElement() {38 return null;39 }40}41public class Test8 {42 public static WebElement getWebElement() {43 return null;44 }45}

Full Screen

Full Screen

presenceOfNestedElementLocatedBy

Using AI Code Generation

copy

Full Screen

1package com.swtestacademy;2import org.openqa.selenium.By;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.WebElement;5import org.openqa.selenium.chrome.ChromeDriver;6import org.openqa.selenium.support.ui.ExpectedConditions;7import org.openqa.selenium.support.ui.WebDriverWait;8public class WaitNestedElement {9 public static void main(String[] args) {10 System.setProperty("webdriver.chrome.driver", "C:\\Users\\vishn\\Downloads\\chromedriver_win32\\chromedriver.exe");11 WebDriver driver = new ChromeDriver();12 driver.findElement(By.linkText("Selenium")).click();13 WebDriverWait wait = new WebDriverWait(driver, 10);14 element.click();15 driver.quit();16 }17}

Full Screen

Full Screen

presenceOfNestedElementLocatedBy

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.WebDriver;2import org.openqa.selenium.firefox.FirefoxDriver;3import org.openqa.selenium.support.ui.ExpectedConditions;4import org.openqa.selenium.support.ui.WebDriverWait;5import org.openqa.selenium.By;6import java.util.concurrent.TimeUnit;7public class PresenceOfNestedElementLocatedBy {8public static void main(String[] args) {9WebDriver driver = new FirefoxDriver();10driver.manage().window().maximize();11driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);12WebDriverWait wait = new WebDriverWait(driver, 10, 5000);13wait.until(ExpectedConditions.presenceOfNestedElementLocatedBy(By.id("wrapper"), By.id("btn")));14driver.findElement(By.id("btn")).click();15driver.close();16}17}

Full Screen

Full Screen

presenceOfNestedElementLocatedBy

Using AI Code Generation

copy

Full Screen

1package com.company;2import org.openqa.selenium.By;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.WebElement;5import org.openqa.selenium.chrome.ChromeDriver;6import org.openqa.selenium.support.ui.ExpectedConditions;7import org.openqa.selenium.support.ui.WebDriverWait;8import java.util.concurrent.TimeUnit;9public class Main {10 public static void main(String[] args) {11 System.setProperty("webdriver.chrome.driver", "C:\\Users\\user\\Downloads\\chromedriver_win32\\chromedriver.exe");12 WebDriver driver = new ChromeDriver();13 driver.manage().window().maximize();14 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);15 WebDriverWait wait = new WebDriverWait(driver, 10);16 wait.until(ExpectedConditions.elementToBeClickable(childElement));

Full Screen

Full Screen

StackOverFlow community discussions

Questions
Discussion

Appium in Web app: Unable to tap Allow permission button in notification pop up window

Selenium WebDriver: Wait for complex page with JavaScript to load

Getting &quot;org.openqa.selenium.ElementClickInterceptedException&quot; when invoking a CLICK using Selenium Java Test case

How to implement WebDriver PageObject methods that can return different PageObjects

How do I disable Firefox logging in Selenium using Geckodriver?

Selenium Webdriver remote setup

Selenium WebDriver: clicking on elements within an SVG using XPath

Selenium: Change By-instance or concat two By-instances

How to wait until an element no longer exists in Selenium

Cannot find any elements using Internet Explorer 11 and Selenium (any version) and IEWebDriver (any version)

First: capabilities you were trying to use are for IOS only

On Android you have to find popup via findElement and close them yourself.

Second: since you start Appium session for web application, before searching for native popups you must switch the context:

    String webContext = driver.getContext();
    Set<String> contexts = driver.getContextHandles();
    for (String context: contexts){
        if (context.contains("NATIVE_APP")){
            driver.context(context);
            break;
        }
    }
    driver.findElement(By.id("android:id/button1")).click();

Don't forget to switch context back to web to continue:

    driver.context(webContext);
https://stackoverflow.com/questions/51174794/appium-in-web-app-unable-to-tap-allow-permission-button-in-notification-pop-up

Blogs

Check out the latest blogs from LambdaTest on this topic:

Performing Cross Browser Testing with LambdaTest

This article is a part of our Content Hub. For more in-depth resources, check out our content hub on Cross Browser Testing Tutorial.

Gauge Framework – How to Perform Test Automation

Gauge is a free open source test automation framework released by creators of Selenium, ThoughtWorks. Test automation with Gauge framework is used to create readable and maintainable tests with languages of your choice. Users who are looking for integrating continuous testing pipeline into their CI-CD(Continuous Integration and Continuous Delivery) process for supporting faster release cycles. Gauge framework is gaining the popularity as a great test automation framework for performing cross browser testing.

Top 17 Software Testing Blogs to Look Out For in 2019

Software testing is one of the widely aspired domain in the current age. Finding out bugs can be a lot of fun, and not only for testers, but it’s also for everyone who wants their application to be free of bugs. However, apart from online tutorials, manuals, and books, to increase your knowledge, find a quick help to some problem or stay tuned to all the latest news in the testing domain, you have to rely on software testing blogs. In this article, we shall discuss top 17 software testing blogs which will keep you updated with all that you need to know about testing.

Metrics &#038; Challenges For Testing Streaming Applications In 2019

Streaming rich media has become an integral part of our daily lives. From watching tutorials on YouTube, Udemy etc. to playing RPGs(Role-Playing Games) on the internet, a major percentage of internet traffic nowadays spends their data on browsing through audio and video contents. With the data speed increasing day by day, media streaming has become the primary way of spreading information to the crowd.

Guide to Take Screenshot in Selenium with Examples

There is no other automation framework in the market that is more used for automating web testing tasks than Selenium and one of the key functionalities is to take Screenshot in Selenium. However taking full page screenshots across different browsers using Selenium is a unique challenge that many selenium beginners struggle with. In this post we will help you out and dive a little deeper on how we can take full page screenshots of webpages across different browser especially to check for cross browser compatibility of layout.

Selenium 4 Tutorial:

LambdaTest’s Selenium 4 tutorial is covering every aspects of Selenium 4 testing with examples and best practices. Here you will learn basics, such as how to upgrade from Selenium 3 to Selenium 4, to some advanced concepts, such as Relative locators and Selenium Grid 4 for Distributed testing. Also will learn new features of Selenium 4, such as capturing screenshots of specific elements, opening a new tab or window on the browser, and new protocol adoptions.

Chapters:

  1. Upgrading From Selenium 3 To Selenium 4?: In this chapter, learn in detail how to update Selenium 3 to Selenium 4 for Java binding. Also, learn how to upgrade while using different build tools such as Maven or Gradle and get comprehensive guidance for upgrading Selenium.

  2. What’s New In Selenium 4 & What’s Being Deprecated? : Get all information about new implementations in Selenium 4, such as W3S protocol adaption, Optimized Selenium Grid, and Enhanced Selenium IDE. Also, learn what is deprecated for Selenium 4, such as DesiredCapabilites and FindsBy methods, etc.

  3. Selenium 4 With Python: Selenium supports all major languages, such as Python, C#, Ruby, and JavaScript. In this chapter, learn how to install Selenium 4 for Python and the features of Python in Selenium 4, such as Relative locators, Browser manipulation, and Chrom DevTool protocol.

  4. Selenium 4 Is Now W3C Compliant: JSON Wireframe protocol is retiring from Selenium 4, and they are adopting W3C protocol to learn in detail about the advantages and impact of these changes.

  5. How To Use Selenium 4 Relative Locator? : Selenium 4 came with new features such as Relative Locators that allow constructing locators with reference and easily located constructors nearby. Get to know its different use cases with examples.

  6. Selenium Grid 4 Tutorial For Distributed Testing: Selenium Grid 4 allows you to perform tests over different browsers, OS, and device combinations. It also enables parallel execution browser testing, reads up on various features of Selenium Grid 4 and how to download it, and runs a test on Selenium Grid 4 with best practices.

  7. Selenium Video Tutorials: Binge on video tutorials on Selenium by industry experts to get step-by-step direction from automating basic to complex test scenarios with Selenium.

Selenium 101 certifications:

LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful