0

I am trying to find an element in the website that i am trying to automate but am unable to figure out how to fetch a particular element. I have provided the html below. Please provide some inputs. Thanks.

< div id="Troy_combine" class="sign_in_flow sign_in_flow_overlay troy_overlay epc_modal big_dialog modal_display" > < h3 class="migration"> Welcome back.< /h3>< h3 class="normal">Welcome to Disneyland< / h3>< p class="migration">It looks like you have a account that use the same address and password. Let’s combine them into a single account to make it easier to access both services.< /p>

Note: There are multiple "migration" classes. How will it know which one to pick up??

I am trying to fetch the text shown in Italics. Help required

Selenium Webdriver with Java

3 Answers 3

2

I would use a cssSelector like so:

String itext = driver
    .findElement( By.cssSelector("div#Troy_combine p.migration")).getText();
Sign up to request clarification or add additional context in comments.

8 Comments

There are multiple classes with name as "migration". I want to get text of the one having 'p' tag. I am getting element not found exception with above solution
Is the space there between 'combine' and 'p'? Now i am not getting any exception but the string is returned as blank
His code is correct. What happens if you run this: new WebDriverWait(driver, 10).until(ExpectedConditions.textToBePresentInElement(By.cssSelector("div#Troy_combine p.migration"), "It looks like you have a account that use the same address and password. Let’s combine them into a single account to make it easier to access both services."))
I get a timeoutexception when i follow your advice...one thing i want to point out....the full html has multiple 'div' tags. i have copied only the one that I am interested in...Can that be the issue? So I am dealing with multiple 'div' and multiple classes with same name.
the CSS path of the element is shown as below when using Firebug: html body.login div.ui-dialog div#Troy_combine.sign_in_flow p.migration
|
0

Selecting via classes and IDs are always the easiest and most reliable. Do a By.className("migration").

Comments

0

findElement(By.cssSelector("div.migration")).getText();

I think you could select it by ID as well.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.