Convert String to Repo Element
-
- Posts: 254
- Joined: Tue Mar 24, 2015 5:05 pm
- Location: Des Moines, Iowa, USA
Re: Convert String to Repo Element
Ok, I still haven't figured out how to search by the object's full name, but I found what can only be considered black magic over at stackoverflow that seems to work for us.
I just straight up lifted their code and I only have the vaguest idea how it works (as designated by the class name 'Idontevenknow'). The C# notation here is beyond my experience, so I'm not going to really walk you through the lambda stuff.
Rather than trying to explain any of this I've just attached my sample solution. I think this type of thing could be useful to a lot of people. Hopefully others from the community might be able to expand upon this or streamline it somehow.
Good luck and let me know if this solves your problem.
I just straight up lifted their code and I only have the vaguest idea how it works (as designated by the class name 'Idontevenknow'). The C# notation here is beyond my experience, so I'm not going to really walk you through the lambda stuff.
Rather than trying to explain any of this I've just attached my sample solution. I think this type of thing could be useful to a lot of people. Hopefully others from the community might be able to expand upon this or streamline it somehow.
Good luck and let me know if this solves your problem.
You do not have the required permissions to view the files attached to this post.
Doug Vaughan
Re: Convert String to Repo Element
Thanks for helping me in this quest, VaughnVaughan.Douglas wrote:Ok, I still haven't figured out how to search by the object's full name, but I found what can only be considered black magic over at stackoverflow that seems to work for us.
I just straight up lifted their code and I only have the vaguest idea how it works (as designated by the class name 'Idontevenknow'). The C# notation here is beyond my experience, so I'm not going to really walk you through the lambda stuff.
Rather than trying to explain any of this I've just attached my sample solution. I think this type of thing could be useful to a lot of people. Hopefully others from the community might be able to expand upon this or streamline it somehow.
Good luck and let me know if this solves your problem.
Now I'm trying to do something different, based on the method we already discussed here:
Code: Select all
public void v(string repoItemName, Duration timeOut)
{
IEnumerable<RepoItemInfo> myQuery = from things in repo.BO.SIGABOClient.Importacao.SelfInfo.Children
where ReferenceEquals(things.Name, repoItemName)
select things;
myQuery.First().Exists(timeOut);
}
Code: Select all
public void v(string repoItemName, Duration timeOut)
{
IEnumerable<RepoItemInfo> myQuery = from things in repo.BO.SIGABOClient.Importacao.SelfInfo.Children
where ReferenceEquals(things.Name, repoItemName)
select things;
myQuery.First().Click();
}
Is there a way to be able to use our "v" method to perform clicks with the repository items found?'System.Collections.Generic.IEnumerable<Ranorex.Core.Repository.RepoItemInfo>' does not contain a definition for 'Click' and no extension method 'Click' accepting a first argument of type 'System.Collections.Generic.IEnumerable<Ranorex.Core.Repository.RepoItemInfo>' could be found (are you missing a using directive or an assembly reference?) (CS1061) - D:\Repositories\Flow2TestAuto\RanorexStudio Projects\Flow2TestProject\Flow2TestProject\CodeTestProject\FO\FO.cs:140,13
Thanks.
- RobinHood42
- Posts: 324
- Joined: Fri Jan 09, 2015 3:24 pm
Re: Convert String to Repo Element
Hi,
The error message tells you what the problem is
You are using the RepoItemInfo object which has no definition for a click method.
You can try to search for the repository items and not their info objects.
For example: repo.BO.SIGABOClient.Importacao.Children
Cheers,
Robin
The error message tells you what the problem is
You are using the RepoItemInfo object which has no definition for a click method.
You can try to search for the repository items and not their info objects.
For example: repo.BO.SIGABOClient.Importacao.Children
Cheers,
Robin
Re: Convert String to Repo Element
I've tried what you suggested "repo.FO.FLOW2FO.Container2.Children" but I get an error telling me that Ican't use "Children" on my repo-item and if i use "Self.Children" I get a different error. My code is something like this:RobinHood42 wrote:Hi,
The error message tells you what the problem is
You are using the RepoItemInfo object which has no definition for a click method.
You can try to search for the repository items and not their info objects.
For example: repo.BO.SIGABOClient.Importacao.Children
Cheers,
Robin
Code: Select all
for (int i = 0; i < length; i++)
{
string repoItemName = "Button" + arrayOfCharacters[i].ToString();
IEnumerable<RepoItemInfo> myQuery = from things in repo.FO.FLOW2FO.Container2.Self.Children
where ReferenceEquals(things.Name, repoItemName)
select things;
myQuery.Click();
}
Code: Select all
'Ranorex.Unknown' does not contain a definition for 'Name' and no extension method 'Name' accepting a first argument of type 'Ranorex.Unknown' could be found (are you missing a using directive or an assembly reference?) (CS1061) - D:\Repositories\Flow2TestAuto\RanorexStudio Projects\Flow2TestProject\Flow2TestProject\CodeTestProject\FO\FO.cs:122,35
Code: Select all
'System.Collections.Generic.IEnumerable<Ranorex.Core.Repository.RepoItemInfo>' does not contain a definition for 'Click' and no extension method 'Click' accepting a first argument of type 'System.Collections.Generic.IEnumerable<Ranorex.Core.Repository.RepoItemInfo>' could be found (are you missing a using directive or an assembly reference?) (CS1061) - D:\Repositories\Flow2TestAuto\RanorexStudio Projects\Flow2TestProject\Flow2TestProject\CodeTestProject\FO\FO.cs:125,13
- RobinHood42
- Posts: 324
- Joined: Fri Jan 09, 2015 3:24 pm
Re: Convert String to Repo Element
Hi xibinki,
Based on your provided code, I have created a small sample. I hope it helps you to meet your requirements :
Robin
Based on your provided code, I have created a small sample. I hope it helps you to meet your requirements :
string repoItemName = "Button1"; //Query RepoItemInfo objects based on the repository item name IEnumerable<RepoItemInfo> myQuery = from things in repo.MyApp.SelfInfo.Children where ReferenceEquals(things.Name, repoItemName) select things; //Create "unkown" adapter for the first found element and click it myQuery.First().CreateAdapter<Unknown>(true).Click();Cheers,
Robin
-
- Posts: 254
- Joined: Tue Mar 24, 2015 5:05 pm
- Location: Des Moines, Iowa, USA
Re: Convert String to Repo Element
You're asking for two very different things. Our initial functionality was about finding an object by name and waiting for it to exist, thus targeting the repoiteminfo. In order to click the object you'll need to target the object itself. (This is what RobinHood42 told mentioned above).xibinki wrote:Is there a way to be able to use our "v" method to perform clicks with the repository items found?
Thanks.
RobinHood42 also provides a reasonable solution
string repoItemName = "Button1"; //Query RepoItemInfo objects based on the repository item name IEnumerable<RepoItemInfo> myQuery = from things in repo.MyApp.SelfInfo.Children where ReferenceEquals(things.Name, repoItemName) select things; //Create "unkown" adapter for the first found element and click it myQuery.First().CreateAdapter<Unknown>(true).Click();The only difference I might suggest is separating the the find from the click.
<UNTESTED>
string repoItemName = "Button1"; //Query RepoItemInfo objects based on the repository item name IEnumerable<RepoItemInfo> myQuery = from things in repo.MyApp.SelfInfo.Children where ReferenceEquals(things.Name, repoItemName) select things; var myElement = _repo.SelfInfo.CreateAdapter<Ranorex.WebElement>(false); try { Host.Local.TryFindSingle(myQuery.First().Path, 50000, out myElement); myElement.Click(); } catch (Exception) { //Throw specific error that provides detailed information throw; }The only real difference is RobinHood42's example will throw an error if the it is unable to create the adapter whereas mine requires you to catch and handle this failure manually which is the way I prefer to deal with this type of situation.
Doug Vaughan
Re: Convert String to Repo Element
Hi Robin,RobinHood42 wrote:Hi xibinki,
Based on your provided code, I have created a small sample. I hope it helps you to meet your requirements :
string repoItemName = "Button1"; //Query RepoItemInfo objects based on the repository item name IEnumerable<RepoItemInfo> myQuery = from things in repo.MyApp.SelfInfo.Children where ReferenceEquals(things.Name, repoItemName) select things; //Create "unkown" adapter for the first found element and click it myQuery.First().CreateAdapter<Unknown>(true).Click();Cheers,
Robin
First of all, thank you so much, that method works indeed!!! Although I'm having the stupidest problem of all time, which is, if I pass:
Code: Select all
string repoItemName = "Button5";
Code: Select all
string repoItemName = "Button" + arrayOfCharacters[i].ToString();
So my question is, why can't I get the method to work when I change on how I "build" my string?Sequence contains no elements
Hope to get an answer from you and thanks once again.
Re: Convert String to Repo Element
Hi Vaughan,Vaughan.Douglas wrote:You're asking for two very different things. Our initial functionality was about finding an object by name and waiting for it to exist, thus targeting the repoiteminfo. In order to click the object you'll need to target the object itself. (This is what RobinHood42 told mentioned above).xibinki wrote:Is there a way to be able to use our "v" method to perform clicks with the repository items found?
Thanks.
RobinHood42 also provides a reasonable solutionstring repoItemName = "Button1"; //Query RepoItemInfo objects based on the repository item name IEnumerable<RepoItemInfo> myQuery = from things in repo.MyApp.SelfInfo.Children where ReferenceEquals(things.Name, repoItemName) select things; //Create "unkown" adapter for the first found element and click it myQuery.First().CreateAdapter<Unknown>(true).Click();The only difference I might suggest is separating the the find from the click.
<UNTESTED>string repoItemName = "Button1"; //Query RepoItemInfo objects based on the repository item name IEnumerable<RepoItemInfo> myQuery = from things in repo.MyApp.SelfInfo.Children where ReferenceEquals(things.Name, repoItemName) select things; var myElement = _repo.SelfInfo.CreateAdapter<Ranorex.WebElement>(false); try { Host.Local.TryFindSingle(myQuery.First().Path, 50000, out myElement); myElement.Click(); } catch (Exception) { //Throw specific error that provides detailed information throw; }The only real difference is RobinHood42's example will throw an error if the it is unable to create the adapter whereas mine requires you to catch and handle this failure manually which is the way I prefer to deal with this type of situation.
I tried your solution (I saw you typed UNTESTED) and it didn't work. At the:
Code: Select all
var myElement = _repo.SelfInfo.CreateAdapter<Ranorex.WebElement>(false);
I tried to remove the "_" and when I run it, it appears to trying to find the element on my string and doesn't do anything .The name '_repo' does not exist in the current context (CS0103)
Ahm, also I have a strange problem, which is, if I build my string as:
Code: Select all
string repoItemName = "Button" + arrayOfCharacters[i].ToString();
But if I build my string as:
Code: Select all
string repoItemName = "Button5";
The strings return the exact same thing "Button5" and I don't understand why I can't use the 1st string construction... any suggestions?
-
- Posts: 254
- Joined: Tue Mar 24, 2015 5:05 pm
- Location: Des Moines, Iowa, USA
Re: Convert String to Repo Element
I've got a severe case of vacation brain, so I woudn't expect it to work You are correct _repo should be just repo as it refers to our repository variable
The point I was making was just to separate the object identification step from the click method to make debugging any actual issues a bit easier. I usually take that approach so I can provide better/customized messages in the execution log. RobinHood42's response should produce the desired results, so you should start there and expand as the need arises.
Instead of using
I would suggest encapsulating your search/click into it's own method and just pass the string:
and call it something like this:
StringToRepoItemRepository repo = StringToRepoItemRepository.Instance;You'll need to add something in the catch exception that tells you what the error is. The reason it appears to have just stalled out is probably because an error was thrown, but since there wasn't anything done in the catch it basically just ignored the error.
The point I was making was just to separate the object identification step from the click method to make debugging any actual issues a bit easier. I usually take that approach so I can provide better/customized messages in the execution log. RobinHood42's response should produce the desired results, so you should start there and expand as the need arises.
Instead of using
myQuery.First().CreateAdapter<Unknown>(true).Click();try using a generic element like WebElement or another depending on your application, I think you might be able to just use Element. I'd have to look at the object structure to know for sure, but I'll leave that legwork to you.
myQuery.First().CreateAdapter<Element>(true).Click();As far as your issue with how you're building the string.... I have no idea, it shouldn't make a difference. Except I know this won't work:
IEnumerable<RepoItemInfo> myQuery = from things in _repo.FO.FLOW2FO.Container2.Self.Children where ReferenceEquals(things.Name, "Button" + arrayOfCharacters.ToString()) select things;
I would suggest encapsulating your search/click into it's own method and just pass the string:
public void ClickTheButton(string repoItemName) { IEnumerable<RepoItemInfo> myQuery = from things in _repo.FO.FLOW2FO.Container2.Self.Children where ReferenceEquals(things.Name, repoItemName) select things; myQuery.Click(); }
and call it something like this:
for (int i = 0; i < length; i++) { ClickTheButton( "Button" + arrayOfCharacters.ToString()); }
Doug Vaughan
Re: Convert String to Repo Element
Vaughan.Douglas wrote:I've got a severe case of vacation brain, so I woudn't expect it to work You are correct _repo should be just repo as it refers to our repository variableStringToRepoItemRepository repo = StringToRepoItemRepository.Instance;You'll need to add something in the catch exception that tells you what the error is. The reason it appears to have just stalled out is probably because an error was thrown, but since there wasn't anything done in the catch it basically just ignored the error.
The point I was making was just to separate the object identification step from the click method to make debugging any actual issues a bit easier. I usually take that approach so I can provide better/customized messages in the execution log. RobinHood42's response should produce the desired results, so you should start there and expand as the need arises.
Instead of usingmyQuery.First().CreateAdapter<Unknown>(true).Click();try using a generic element like WebElement or another depending on your application, I think you might be able to just use Element. I'd have to look at the object structure to know for sure, but I'll leave that legwork to you.myQuery.First().CreateAdapter<Element>(true).Click();As far as your issue with how you're building the string.... I have no idea, it shouldn't make a difference. Except I know this won't work:IEnumerable<RepoItemInfo> myQuery = from things in _repo.FO.FLOW2FO.Container2.Self.Children where ReferenceEquals(things.Name, "Button" + arrayOfCharacters.ToString()) select things;
I would suggest encapsulating your search/click into it's own method and just pass the string:public void ClickTheButton(string repoItemName) { IEnumerable<RepoItemInfo> myQuery = from things in _repo.FO.FLOW2FO.Container2.Self.Children where ReferenceEquals(things.Name, repoItemName) select things; myQuery.Click(); }
and call it something like this:for (int i = 0; i < length; i++) { ClickTheButton( "Button" + arrayOfCharacters.ToString()); }
Tried the encapsulating strategy and it still gives me the "Sequence contains no elements", dammit lol... I've tried a few alternatives but always end up getting the same error message
Re: Convert String to Repo Element
So I found the solution to my problem, along with some help from our fellow friends at stackoverflow
On our method:
I just had to change to:
And everything worked perfectly
On our method:
Code: Select all
for (int i = 0; i < length; i++)
{
if (arrayOfCharacters[i].ToString() == ".") {
repo.FO.FLOW2FO.Container2.BtnComma.Click();
}
else {
repoItemName = "Button" + arrayOfCharacters[i].ToString();
//Query RepoItemInfo objects based on the repository item name
IEnumerable<RepoItemInfo> myQuery = from things in repo.FO.FLOW2FO.Container2.SelfInfo.Children
where ReferenceEquals(things.Name, repoItemName)
select things;
//Create "unkown" adapter for the first found element and click it
myQuery.First().CreateAdapter<Unknown>(true).Click();
}
Code: Select all
where String.Equals(things.Name, repoItemName)
-
- Posts: 254
- Joined: Tue Mar 24, 2015 5:05 pm
- Location: Des Moines, Iowa, USA
Re: Convert String to Repo Element
I'm glad to hear it!And everything worked perfectly
xibinki
Doug Vaughan
Re: Convert String to Repo Element
If you prefer working in Visual Studio (as we do) because of the performance benefits when writing and debugging, then vote here:
http://uservoice.ranorex.com/forums/150 ... -webdriver
Let's get Ranorex to support the WebDriver via their API!!!
http://uservoice.ranorex.com/forums/150 ... -webdriver
Let's get Ranorex to support the WebDriver via their API!!!