Make cell into a Checkbox?

Ask general questions here.
MJesper
Posts: 26
Joined: Fri Dec 28, 2018 2:16 pm

Make cell into a Checkbox?

Post by MJesper » Thu Jan 24, 2019 4:02 pm

Hi I have a grid with checkboxes and need to make a cell into a "Checkbox" adapter. How would I do that? Doing .As<Checkbox> returns null

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

Re: Make cell into a Checkbox?

Post by odklizec » Fri Jan 25, 2019 9:31 am

Hi,

Could you please post a Ranroex snapshot of the problematic table/cell and describe in more details, what exactly you are trying to achieve? I don't think you can easily convert 'cell' to 'checkbox', if cell does not have such capability? But I may be wrong and I will learn something new today? :D
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

MJesper
Posts: 26
Joined: Fri Dec 28, 2018 2:16 pm

Re: Make cell into a Checkbox?

Post by MJesper » Fri Jan 25, 2019 9:50 am

Yea no you can't convert a cell element to a checkbox.. So I was kindof wondering if there's some sort of "CellCheckbox" , apparently not :( . Here's a workaround I did, might help someone in the future:

Code: Select all

		private readonly Cell context;
		
		public bool Ticked 
		{
			get
			{
				var state = this.context.Element.GetAttribute<string>(AttributeType.AccessibleValue);
				
				if(state == "Checked")
				{
					return true;
				}
				if(state == "Unchecked")
				{
					return false;
				}
				
				throw new Exception("This isn't a checkbox");
			}
		}
		
		public CheckboxCell(Cell context)
		{
			this.context = context;
		}
		
		public void Tick()
		{
			if(!this.Ticked)
			{
				this.context.Click();
			}
		}
		
		public void Untick()
		{
			if(this.Ticked)
			{
				this.context.Click();
			}
		}
	}