点击<a> tag with selenium c#

时间:2017-12-28 18:15:31

标签: c# html selenium-webdriver

I am trying to click on a <a> tag but when I am trying to access it by ID i got an error that says Unable to locate element.

I am using selenium c# in unit test project. the code to make the click is the followining:

IWebdriver.FindElement(By.Id("BUTTON_OPEN_SAVE_btn0_acButton")).Click();

and <a> tag code is the following:

<a id="BUTTON_OPEN_SAVE_btn0_acButton" ct="B" title="New Analysis of Existing Data" st="" href="javascript:void(0);" class="urBtnStd" ocl="sapbi_page.sendCommandArray([['BI_COMMAND_TYPE','LOAD',0],['TARGET_DATA_PROVIDER_REF','DP_1',0],['OPEN_SAVE_DIALOG_LAYOUT','DATAPROVIDER_PERSISTENCY',0]],event);" onkeydown="ur_Button_keypress(event);" onclick="ur_Button_click(event);" style="width:0;width:0;">New Analysis</a>

2 个答案:

答案 0 :(得分:0)

试试这个:

IWebdriver.FindElement(By.XPath("//a[@class='urBtnStd']")).Click();

答案 1 :(得分:0)

要点击button,文字为 New Analysis ,您可以使用以下代码行:

IWebdriver.FindElement(By.XPath("//a[@class='urBtnStd' and [contains(.,'New Analysis')]]")).Click();