使用java的带有空格的webdriver类名

webdriver classname with space using java(使用java的带有空格的webdriver类名)
本文介绍了使用java的带有空格的webdriver类名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题在 jquery 中得到了很好的答案,我想知道是否有人可以在 Java 中给出 this 的示例?

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

我在做 driver.findElement(By.className("current time")).click(); 空间是问题,我在链接上看到了解释,但是我'不知道如何在java中处理它,并且无权更改类名.

I'm doing driver.findElement(By.className("current time")).click(); The 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.

我在 firefox 检查 id 中得到的粘贴示例:下面带有 cssSelector 的示例不起作用,但我可能遗漏了一些东西.

Pasting example of what i get in the firefox inspect id: Example with cssSelector 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>

推荐答案

您可以使用 css 选择器代替类名.您没有提及当前时间"类的标记名.我假设它是输入的,所以你的 css 选择器可以工作,

Instead of class name you can use a css selector. You don't mention the tagname for the class 'current time'. I am assuming it to be input, so your css selector work be,

WebElement element = driver.findElement(By.cssSelector("input[class='current time']"));
element.click();

Edit#1基于提供的html,

查看您评论中的 html,您似乎有很多选项可以找到 webElement.这是您的选择,

Looking at the html in your comment, it seems you have quite a few options to find the webElement. Here are your options,

WebElement element = driver.findElement(By.cssSelector("a[class='current time']"));
element.click();

或者这也应该有效,

WebElement element = driver.findElement(By.cssSelector("a.current.time"));
element.click();

你也可以使用linkText,因为元素是链接.从您提供的 html 中,链接文本是 'url'

You can also use linkText since the element is link. From the html you provided, the link text is 'url'

WebElement element = driver.findElement(By.linkText("url"));
element.click();

也可以使用By.partialLinkText("partial link text here");

您也可以将 xpath 用作:

You can also use xpath as:

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

或,

WebElement element = driver.findElement(By.xpath("//a[text() = 'url']"));
element.click();

这篇关于使用java的带有空格的webdriver类名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How can create a producer using Spring Cloud Kafka Stream 3.1(如何使用Spring Cloud Kafka Stream 3.1创建制片人)
Insert a position in a linked list Java(在链接列表中插入位置Java)
Did I write this constructor properly?(我是否正确地编写了这个构造函数?)
Head value set to null but tail value still gets displayed(Head值设置为空,但仍显示Tail值)
printing nodes from a singly-linked list(打印单链接列表中的节点)
Control namespace prefixes in web services?(控制Web服务中的命名空间前缀?)