0

Is it possible to combine these two Xpaths into one xpath query?

signatureAgreementThumbnailForInProgressApplication = By.XPath("//div[text()='Upload Signature Agreement']/parent::div/parent::div/descendant::div[contains(@style,'background-image: url')]");
signatureAgreementThumbnailForSubmittedApplication = By.XPath("//div[text()='Signature Agreement']/parent::div/descendant::div[contains(@style,'background-image: url')]");

My automation test (project is VS/C#/Selenium) requires validating the presence (but not content or anything else) of document thumbnails for two statuses of an online application: in-progress and submitted. I feel two separate methods with different xpaths is redundant, since I am doing the same simple validation.

After looking through SO posts which suggested using and/or to evalute multiple attributes, I created this below query which works almost perfectly for both In-Progress and Submitted thumbnails. Minor issue is that for Submitted, in DOM, the xpath hits two thumbnail elements, the one I want it to hit and another one. My test still passes since it is validating thumbnail presence, but I am hoping to tweak it so it finds the specific thumbnail.

signatureAgreementThumbnail = By.XPath("//div[text()='Upload Signature Agreement' or text()='Signature Agreement']/parent::div/parent::div/descendant::div[contains(@style,'background-image: url')]");

I also tried the following queries, which do not work at all:

//div[text()='Upload Signature Agreement' or text()='Signature Agreement'][/parent::div/parent::div/descendant::div or /parent::div/descendant::div][contains(@style,'background-image: url')]
//div[text()='Upload Signature Agreement' or text()='Signature Agreement'][/parent::div/parent::div/descendant::div or /parent::div/descendant::div and contains(@style,'background-image: url')]

I cannot provide the URL of the site I am automating since it is a private site.

Anne Bailly
  • 391
  • 3
  • 9
  • See if this helps https://stackoverflow.com/a/73226797/2834978 – LMC Aug 06 '22 at 23:16
  • There's really not enough information here to answer your question. Can you provide a sample of the HTML? At least the part which includes the "two thumbnail elements, the one I want it to hit and another one"? It's impossible to say how you might distinguish between these two thumbnails, in the absence of actual data. – Conal Tuohy Aug 07 '22 at 01:53

0 Answers0