matthiasgh
matthiasgh

Reputation: 321

Search for a button by its HTML Code

I am writing Coded UI Test's for a web app. I am having problems such as I record actions using the test builder, however sometimes the button that is clicked has different information each time I run the test and as result VS can't find the button.

The html code never changes so what I want to do is find the button by its html code and click it that way.

For example on Google the path to the search button is

<button id="gbqfba" aria-label="Google Search" name="btnK" class="gbqfba"><span id="gbqfsa">Google Search</span></button>

How can I click this button using the code above or Alternativly using the XPath

//*[@id="gbqfba"]

Any help would be greatly appreciated.

Upvotes: 1

Views: 778

Answers (3)

Prateek Garg
Prateek Garg

Reputation: 56

This will do the trick:

BrowserWindow.ExecuteScript("$('#gbqfba').click();");

Upvotes: 0

KingM0ses
KingM0ses

Reputation: 64

adjust the Search Properties and Filter Properties.

Upvotes: 1

matthiasgh
matthiasgh

Reputation: 321

I found the answer, If you go to the UIMap.uitest file and click the method you have the problem with you can change the filter properties and the search properties to remove parts that are failing your test.

Upvotes: 0

Related Questions