I want to assert a client name which is present inside the div tags.
Below is the HTML code.
<div class="row">
<div class="col-md-2 dl-no-margin-bottom">
</div>
<div class="col-md-5 dl-no-margin-bottom">
<label class="dl-padding-top-5">Client Name:</label>
<br>
<label class="dl-font-robotolight dl-font-14" id="clientName1eb0d7867">MOLOANTOA MOTAUNG</label>
</div>
<div class="col-md-5 dl-no-margin-bottom">
<label class="dl-padding-top-5">Client Name at Bureau:</label>
<br>
<label class="dl-font-robotolight dl-font-14" id="clientName2eb0d7867">MOLOANTOA MOTAUNG</label>
</div>
</div>
</div>
i want to assert the names of the ID:clientName1eb0d7867 & clientName2eb0d7867.But i am unable to locate the element with below code were i am getting unable to locate element error.
String actual_clientname = driver.FindElement(By.Id("clientName1cb737f0d")).Text;
String expected_clientname = "MOLOANTOA MOTAUNG";
Assert.AreEqual(actual_clientname, expected_clientname);
Console.WriteLine("Client Name validated successfully");
String actual_Bureauname = driver.FindElement(By.Id("clientName2cb737f0d")).Text;
String expected_Bureauname = "MOLOANTOA MOTAUNG";
Assert.AreEqual(actual_Bureauname, expected_Bureauname);
Console.WriteLine("Client Name validated successfully");
Also tried,
//*[@class='dl-font-robotolight dl-font-14'][@id='clientName1cb737f0d']"));
But getting the same error.
what is the right way to do it? kindly suggest.
When I see a value like "clientName1cb737f0d" this is usually dynamically driven each time with the alphanumeric value of "1cb737f0d"?
If so, can you try something like this?
var name = driver.FindElement(By.Xpath("//label[text()='Client Name:']/following-sibling::label")).Text;
var bureau = var bureau = driver.FindElement(By.XPath("//label[text()='Client Name at Bureau:']/following-sibling::label")).Text;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.