Unable to get Style of Element

Ask general questions here.
n.tazouti
Posts: 3
Joined: Mon May 03, 2021 1:44 pm

Unable to get Style of Element

Post by n.tazouti » Mon May 03, 2021 3:26 pm

Hello everyone ,
I'm trying to write a function that detects if an element is written in bold or italic.
If i directly give the element like follow :IT DOES WORK !

public static void CheckIfBold(){
var dayInTransferWeek = PumaRepo.ApplicationUnderTest.dayInTransferWeek;
String font = dayInTransferWeek.GetStyle("font-weight");
Validate.AreEqual("700", font);
Report.Info("element gras"+font);
}
But i want to generalize it the way i give the function the element i want , so i have written this function but IT doesnt work

public static void CheckIfElementIsBold(RepoItemInfo Element){
String font = Element.GetStyle("font-weight");
Validate.AreEqual("700" , font);
Report.Info("element gras"+font);
}
}
I get this error
'Ranorex.Core.Repository.RepoItemInfo' ne contient pas une définition pour 'GetStyle' et aucune méthode d'extension 'GetStyle' acceptant un premier argument de type 'Ranorex.Core.Repository.RepoItemInfo' n'a été trouvée (une directive using ou une référence d'assembly est-elle manquante ?) (CS1061)
please help!

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

Re: Unable to get Style of Element

Post by odklizec » Mon May 03, 2021 3:59 pm

Hi,

Just rename “Element” to something else. Like. “repoElement”. “Element” is a reserved keyword so it confuses Ranorex if used like you did it 😉
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

n.tazouti
Posts: 3
Joined: Mon May 03, 2021 1:44 pm

Re: Unable to get Style of Element

Post by n.tazouti » Mon May 03, 2021 4:06 pm

Hello ,
I did what u said
public static void CheckIfElementIsBold(RepoItemInfo repoElement){
String font = repoElement.GetStyle("font-weight");
Validate.AreEqual("700" , font);
Report.Info("element gras"+font);
}
}
I get the same error , telling 'Ranorex.Core.Repository.RepoItemInfo'doesnt contain definition of 'GetStyle'

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

Re: Unable to get Style of Element

Post by odklizec » Mon May 03, 2021 5:58 pm

Hi,

Sorry, my mistake. I forgot to mention that you must create an adapter from RepoItemInfo object. Like this:

Code: Select all

repoElement.CreateAdapter<Ranorex.WebElement>(true).GetStyle("font-weight");
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

n.tazouti
Posts: 3
Joined: Mon May 03, 2021 1:44 pm

Re: Unable to get Style of Element

Post by n.tazouti » Mon May 03, 2021 6:09 pm

It worked ! Thanks a lot :D