0

Trying to Automate the test case. Please anyone explain me how can I locate span class element? Or even more, how to locate an element within an element and afterwards select from the drop down list? Few hours of work are in vain...

This is the class I am trying to locate:

<span class="labelText___1_7Q2">Erstzulassung ab</span>

This is the structure of the task I am trying to execute:

drop down menu

HTML source code

Thank you in advance.

asked Mar 18, 2019 at 22:37

1 Answer 1

1

You can find the above span by using the xpath:

WebElement element = driver.findElement(By.xpath("//span[text()='Erstzulassung ab']"));

And you can also parameterise the xpath if you want to use the same xpath to select different elements with different values like:

String text = null;
WebElement element1 = driver.findElement(By.xpath("//span[text()="+text+"]"));

And then you can just send the expected value in the text string here or you can just directly set the xpath like the first one i have used.

answered Mar 19, 2019 at 2:03
Sign up to request clarification or add additional context in comments.

1 Comment

You should replace null with 'Erstzulassung ab' for a more clear example. Setting text to null and then using it is going to throw an exception.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.