Java 如何单击Span类元素
我需要找到编辑器的HTML代码Java 如何单击Span类元素,java,html,testing,selenium,automation,Java,Html,Testing,Selenium,Automation,我需要找到编辑器的HTML代码 <span class="td-creative-name"></span> <div class="editors pull-right" style="visibility: visible;"> <ul id="editorList"> <li></li> <li></li> <li>
<span class="td-creative-name"></span>
<div class="editors pull-right" style="visibility: visible;">
<ul id="editorList">
<li></li>
<li></li>
<li>
<span class="dc-url omedia-link" title="" data-placement="top" rel="tooltip" data-toggle="tooltip" data-original-title="Creative URL"></span>
</li>
<li></li>
</ul>
-
我想点击这里的“创意URL”。你能帮我查一下密码吗?我无法使它工作 在span中使用jquery put id尝试下面的代码
$("#myspan").click(function(){
alert('I got a click');
});
谢谢
MahaHTML
元素有一个可以使用的onclick
属性。有关示例,请参见以下jfiddle:
在本例中,您希望填写span
标记的onclick
属性:
<span class="dc-url omedia-link" title=""
data-placement="top" rel="tooltip"
data toggle="tooltip" data-original-title="Creative URL"
onclick="yourFunction();"></span>
如果您使用的是selenium,那么您可以找到元素并单击它
driver.findElement(By.xpath("//*[@class='dc-url omedia-link')]")).click();
注意:如果我提到的xpath不起作用,请使用css选择器或任何其他工具。除了已经发布的HTML之外,您还可以发布您迄今为止尝试过的selenium代码吗?我很好奇您是在使用旧的selenium还是selenium 2(WebDriver)。WebDriverWait wait3=新的WebDriverWait(wd,300);wait3.until(ExpectedConditions.presenceOfElementLocated(By.xpath(“//*[contains(@class,'dc-url-omedia link')])));wd.findElement(By.xpath(“/*[contains(@class,'dc-url omedia link')])))。单击();但这并没有采取任何行动。你能帮我让它工作吗?嗨,我试过这个java代码。WebDriverWait wait3=新的WebDriverWait(wd,300);wait3.until(ExpectedConditions.presenceOfElementLocated(By.xpath(“//*[contains(@class,'dc-url-omedia link')])));wd.findElement(By.xpath(“/*[contains(@class,'dc-url omedia link')])))。单击();但这并没有采取任何行动。你能帮我让它工作吗?嗨,我试过这个java代码。WebDriverWait wait3=新的WebDriverWait(wd,300);wait3.until(ExpectedConditions.presenceOfElementLocated(By.xpath(“//*[contains(@class,'dc-url-omedia link')])));wd.findElement(By.xpath(“/*[contains(@class,'dc-url omedia link')])))。单击();但这并没有采取任何行动。你能帮我让它工作吗?嗨,我试过这个java代码。WebDriverWait wait3=新的WebDriverWait(wd,300);wait3.until(ExpectedConditions.presenceOfElementLocated(By.xpath(“//*[contains(@class,'dc-url-omedia link')])));wd.findElement(By.xpath(“/*[contains(@class,'dc-url omedia link')])))。单击();但这并没有采取任何行动。你能帮我让它工作吗?嗨,我试过这个java代码。WebDriverWait wait3=新的WebDriverWait(wd,300);wait3.until(ExpectedConditions.presenceOfElementLocated(By.xpath(“//*[contains(@class,'dc-url-omedia link')])));wd.findElement(By.xpath(“/*[contains(@class,'dc-url omedia link')])))。单击();但这并没有采取任何行动。您能帮助它工作吗。@AutoMationBegginer元素存在吗?你的等待失败了吗?请使用ElementLocated的visibilityOfElementLocated而不是presenceOfElementLocated,然后重试。它不起作用。它不执行任何操作,也不抛出任何错误。。任何ideas@AutoMationBegginer如果元素未显示或位于其他帧中,请使用isDisplayed/using size()检查元素是否存在,等等
driver.findElement(By.xpath("//*[@class='dc-url omedia-link')]")).click();