我如何单击提交按钮 [英] How can i click submit button

查看:166
本文介绍了我如何单击提交按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在给定的html上单击提交"按钮

How can i click on submit button on the given html

<span class="sbt-btn-wrap relative">
<input class="submit icon" type="submit" onclick="submitmnLogin($(this), 'testPrepLogin');trackGaEvent('Content Hub Home','Login Popup','Login Button');">

我尝试过

driver.findElement(By.className("sbt-btn-wrap relative")).click();

driver.findElement(By.className("submit icon")).click();

但是它不起作用.

推荐答案

当两个类名之间用空格分隔时,则不能在其上使用By.className.而是使用By.cssSelector单击该元素.这是-

When you have two class names with space separating them, then you cannot use By.className on it. Instead use By.cssSelector to click on the element. Here's how -

driver.findElement(By.cssSelector(".submit.icon")).click();

如果您仍要使用className,请使用该元素唯一的一个类名,然后单击它-

If you still want to use className then use one class name that is unique to the element and click on it -

driver.findElement(By.className("submit")).click();

您可以使用其他属性来单击输入元素.我更喜欢使用cssSelector而不是xpath-

You can use other attributes to click the input element. I prefer using cssSelector instead of xpath as its slow -

driver.findElement(By.cssSelector("input[type='submit']")).click();

这里也是xpath的示例-

Here's an example of xpath too -

driver.findElement(By.xpath("//input[@type='submit']")).click();

如果您无法以唯一的方式找到提交"按钮元素,请使用其他唯一的元素来找到输入元素.

If you are not able to find submit button element in a unique way then use other unique element to find input element.

driver.findElement(By.cssSelector(".sbt-btn-wrap relative .submit")).click();

希望有帮助.

这篇关于我如何单击提交按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆