Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

This question received great answers in jquery and I was wondering if someone could give an example of this in Java, please?

I'm doing driver.findElement(By.className("current time")).click(); space is the issue, and I see the explanation at the link, but I'm not sure how to handle it in java and don't have access to change the class name.

Pasting example of what I get in the firefox inspect id: Example with CSS selector below did not work, but I may be missing something.

<span>

<a class="current time" href="http://someurl/"   onclick="s_objectID="http://someur/">url</a>

</span>

1 Answer

0 votes
by (62.9k points)

For a less fragile test, another option is to use an XPath, which doesn't depend on the order of classes, here’s the code snippet:

WebElement element = driver.findElement(By.xpath("//a[contains(@class, 'current') and contains(@class, 'time')]"));

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...