According to JavaDocs, you can do this:
WebElement input = divA.findElement(By.xpath(".//input"));
How can I ask in xpath for “the div-tag that contains a span with the
text ‘hello world'”?
WebElement elem = driver.findElement(By.xpath("//div[span[text()='hello world']]"));
The XPath spec is a suprisingly good read on this.
More Related Contents:
- How to solve the error “Not a valid XPath expression”
- Selenium WebDriver: clicking on elements within an SVG using XPath
- ‘UnexpectedTagNameException’ and Element should have been “select” but was “div” error using ‘Select’ function through Selenium java
- What is the difference between ChromeDriver and WebDriver in selenium?
- Selenium Web Driver & Java. Element is not clickable at point (x, y). Other element would receive the click
- Element MyElement is not clickable at point (x, y)… Other element would receive the click
- Wait for page load in Selenium
- How to get HTTP Response Code using Selenium WebDriver
- How can I ask the Selenium-WebDriver to wait for few seconds in Java?
- Selenium WebDriver How to Resolve Stale Element Reference Exception?
- Exception in thread “main” org.openqa.selenium.NoSuchElementException: Unable to locate element: //*[@id=’login-email’]
- Cannot resolve constructor FirefoxDriver(org.openqa.selenium.firefox.FirefoxProfile)
- The type FluentWait is not generic; it cannot be parameterized with arguments error for FluentWait Class through Selenium and Java
- How to handle print dialog in Selenium?
- How to select an item from a dropdown list using Selenium WebDriver with java?
- Equivalent of waitForVisible/waitForElementPresent in Selenium WebDriver tests using Java?
- Is there a way to use Selenium WebDriver without informing the document that it is controlled by WebDriver?
- How to check if an element is visible with WebDriver
- How to send cookies with selenium webdriver?
- Tools for measuring UI Performance [closed]
- java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;I)V with IE and Selenium through Java
- How to Conceal WebDriver in Geckodriver from BotD in Java?
- How to select the auto suggestion from the dynamic dropdown using Selenium and Java
- org.openqa.selenium.ElementClickInterceptedException: element click intercepted error using Selenium and Java in headless mode
- Selenium WebDriver StaleElementReferenceException
- Compound class names are not supported error in WebDriver
- How to wait for either of the two elements in the page using selenium xpath
- Exception in thread “main” java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;)
- How to deal with file uploading in test automation using selenium or webdriver
- How to mouse hover using java through selenium-webdriver and Java