使用java的空间webdriver类名

编程入门 行业动态 更新时间:2024-10-10 19:18:43
本文介绍了使用java的空间webdriver类名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这个问题在jquery中得到了很好的答案,我想知道是否有人能用Java提供这个的例子吗?

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(当前时间))。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="someurl/" onclick="s_objectID="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();

编辑#1 根据提供的html,

Edit#1 Based on html provided,

查看评论中的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(此处为部分链接文字) ;

您还可以将xpath用作:

You can also use xpath as:

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

OR,

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

更多推荐

使用java的空间webdriver类名

本文发布于:2023-11-27 22:44:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639909.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:空间   java   webdriver

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!