Page 1 of 1

ButtonInfo Shows Exists, but Click Can't Find Button

Posted: Thu Oct 25, 2018 4:00 pm
by karltinsly
I have a popup watcher that had been working but stopped working yesterday. After experimenting with timing and other things, I decided to disable the popup watcher and just use a simple piece of user code to detect the button I want to click and to click it. The code is detecting the button (using button info), but can't find the button to click.

Here's the code - I added the report.info lines for troubleshooting purposes, and the Focus line based on a suggestion in another post. When run, report shows that the button exists, but then says it can't find the button.

Code: Select all

        public void ClickReadLater()
        {   
        	if (repo.HighPriorityNewsItemAlert.ReadLaterInfo.Exists(new Duration(3000))){
        		Report.Info("Read later exists!");
        		repo.HighPriorityNewsItemAlert.ReadLater.Focus();
        		repo.HighPriorityNewsItemAlert.ReadLater.Click();
        	 	} else {Report.Info("Read later does not exist.");}
      }  
Any help would be appreciated!

Re: ButtonInfo Shows Exists, but Click Can't Find Button

Posted: Thu Oct 25, 2018 6:28 pm
by karltinsly
Well, I got this working. Not sure why this happened, but at least it's working now.

What I did was change the repository item for the button to use accessiblename instead of name. Works fine now.

If anyone has any input as to what caused this problem, I'd like to hear it. We're concerned, because this isn't the first time that something we built ran fine for weeks or months and then suddenly stopped. Sometimes it's obvious what happened - usually a configuration or code change - but other times we're unable to figure it out. Any clues of things to look at when a test stops working would be helpful to know.

Re: ButtonInfo Shows Exists, but Click Can't Find Button

Posted: Fri Oct 26, 2018 10:11 am
by odklizec
Hi,

Are you sure the xpath behind the repo element repo.HighPriorityNewsItemAlert.ReadLater returns just one item? Could you please save a Ranorex snapshot (right after Exists() check) and validate that the xpath is valid just for this one element, and not multiple elements?

Additionally, I personally would never hardcode a repo element in code. Try to use method like this instead:

Code: Select all

		public void ClickReadLater(RepoItemInfo repoElementName)
		{
			if (repoElementName.Exists(new Duration(3000)))
			{
				Report.Info("Read later exists!");
				Ranorex.Unknown elementAdapter = repoElementName.CreateAdapter<Ranorex.Unknown>(false);
				elementAdapter.Focus();
				elementAdapter.Click();
			} else
			{
				Report.Info("Read later does not exist.");
			}
		}
Where repoElementName, should be linked with item from repository. Of course, you can replace "Unknown" with proper adapter type.