如何通过C#单击selenium webdriver中的DOM元素 [英] How to click the DOM element in selenium webdriver thru C#

查看:199
本文介绍了如何通过C#单击selenium webdriver中的DOM元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Firefox中通过Selenium webdriver进行网站自动化。一切都很好,但我不知道如何点击单选按钮。



网上有两个单选按钮(i)家庭信息和(ii)个人信息。在Selenium IDE中获取的目标信息。 (i)name = indFamily(ii)document.pebPostLogin.indFamily [1]



我可以通过以下代码轻松点击第一个家庭信息:

I m doing the website automation thru Selenium webdriver in Firefox. Everything is fine but I dont know how to click the radio button.

There are two radio buttons in the web (i) Family Information and (ii) Individual Information. Target information obtained in the Selenium IDE. (i) name=indFamily (ii) document.pebPostLogin.indFamily[1]

I can easily click the first one Family information thru following code:

driver.FindElement(By.Name("indFamily")).Click();





但是不知道第二个个人信息的C#命令。我在Firefox中记录了Selenium IDE中的操作并导出到C#文件中,但是没有在C#中导出DOM命令。在C#文件中看到以下错误消息。



But dont know the C# command for the second one "Individual Information". I have recorded the actions in Selenium IDE in Firefox and exported into C# file but DOM commands are not exported in C#. Following error message seen in C# file.

// ERROR: Caught exception [Error: Dom locators are not implemented yet!]





请在下面找到通过以下标识的源代码Firebug。





Please find below the source code identified thru Firebug.

<input name="indFamily" tabIndex="6" onkeypress="submitOnEnter(window.event.keyCode, document.pebPostLogin)" type="radio" value="Family"/>
<input name="indFamily" tabIndex="7" onkeypress="submitOnEnter(window.event.keyCode, document.pebPostLogin)" type="radio" value="Individual"/>





请帮帮我...



Please help me out...

推荐答案

它已使用Xpath修复。代码如下:



It has been fixed using Xpath. The code is below:

driver.FindElement(By.XPath("//input[@value='Individual']")).Click();





感谢http://www.w3schools.com/xpath/xpath_syntax.asp



Thanks to http://www.w3schools.com/xpath/xpath_syntax.asp


这篇关于如何通过C#单击selenium webdriver中的DOM元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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