Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception with data type "Two Options" and no default value #46

Closed
WinniB opened this issue Nov 20, 2017 · 3 comments
Closed

Exception with data type "Two Options" and no default value #46

WinniB opened this issue Nov 20, 2017 · 3 comments

Comments

@WinniB
Copy link

WinniB commented Nov 20, 2017

There is an exception when I try to set the value of an element with data type "Two Options" and no default value and when option was never set. Because of the unset state of the element the GetAttribute("checked") returns null. The parsing of null to a Boolean value throws an exception.

@dtu11
Copy link
Member

dtu11 commented Dec 4, 2017

Can you provide the version you're working with and the code of your test script?

Thanks

@WinniB
Copy link
Author

WinniB commented Dec 5, 2017

Sorry, my description was bad, i try to explain it more detailed: I want to check a checkbox on page. The first error occured was that the element could not be found. This is because in the "SetValue" function the element id get the "int_" prefix.
In order to use the "SetValue" function i had to change the id from "int_" + field to field
After this change the driver is now able to find the checkbox, but when .GetAttribute("checked") is executed I get an exception: "Value cannot be null. Parameter name: value"

  • We use Microsoft Dynamics 365 Version 1612 (8.2.2.136) on-premises
  • The code I try to ckeck the checkbox : entity.SetValue("my_checkbox", true);
  • The code after changing the "SetValue" function:
public BrowserCommandResult<bool> SetValue(string field, bool check)
{
	return this.Execute(GetOptions($"Set Value: {field}"), driver =>
	{
		if (driver.HasElement(By.Id(field)))
		{
			var input = driver.FindElement(By.Id(field));

			if (bool.Parse(input.FindElement(By.TagName("input")).GetAttribute("checked")) && !check)
				input.FindElement(By.TagName("input")).Click();
		}
		else
			throw new InvalidOperationException($"Field: {field} Does not exist");

		return true;
	});
}

@j621z
Copy link
Member

j621z commented Dec 15, 2017

@WinniB This fix will be pushed soon. In the mean time, please try running this code. The issue is the "checked" attribute is not present in the "input" tag.

public BrowserCommandResult<bool> SetValue(string field, bool check)
{
	return this.Execute(GetOptions($"Set Value: {field}"), driver =>
	{
		if (driver.HasElement(By.Id(field)))
		{
			var input = driver.FindElement(By.Id(field));
			var checkBox = input.FindElement(By.TagName("input"));
			var bCheck = checkBox.GetAttribute("value") == "1";

			if (bCheck != check)
			{
				checkBox.Click();
			}
		}
		else
			throw new InvalidOperationException($"Field: {field} Does not exist");

		return true;
	});
}

@j621z j621z closed this as completed Dec 18, 2017
dtu11 added a commit that referenced this issue Dec 21, 2017
Issue #49
Issue #50
Issue #58
Issue #57
Issue #55
Issue #48
Issue #46
Issue #40
dtu11 added a commit that referenced this issue Dec 21, 2017
Issue #49
Issue #50
Issue #58
Issue #57
Issue #55
Issue #48
Issue #46
Issue #40
dtu11 added a commit that referenced this issue Dec 21, 2017
Issue #49
Issue #50
Issue #58
Issue #57
Issue #55
Issue #48
Issue #46
Issue #40
@dtu11 dtu11 mentioned this issue Dec 21, 2017
dtu11 added a commit that referenced this issue Dec 21, 2017
Issue #49
Issue #50
Issue #58
Issue #57
Issue #55
Issue #48
Issue #46
Issue #40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants