ButtonInfo Shows Exists, but Click Can't Find Button

Ask general questions here.
karltinsly
Posts: 10
Joined: Tue Jun 07, 2016 9:59 pm

ButtonInfo Shows Exists, but Click Can't Find Button

Post by karltinsly » Thu Oct 25, 2018 4:00 pm

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!

karltinsly
Posts: 10
Joined: Tue Jun 07, 2016 9:59 pm

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

Post by karltinsly » Thu Oct 25, 2018 6:28 pm

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.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3908
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

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

Post by odklizec » Fri Oct 26, 2018 10:11 am

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.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration