troc
troc

Reputation: 43

Cannot locate class span element with Selenium + Java

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.

Upvotes: 0

Views: 199

Answers (1)

Sameer Arora
Sameer Arora

Reputation: 4507

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.

Upvotes: 1

Related Questions