I am trying to write a function in selenium to check if a Reasons dropdown is showing as disabled, but can't quite get the xpath right. The code for the dropdown is in the pic, the function I'm working on is the second one (InputDisabled), having based it on the working first one (SearchDisabled):
` public By SearchDisabled(string searchId) => By.XPath($"//div[@id='{searchId}']//div[contains(@class, 'v-input--is-disabled')]");
public By InputDisabled(string inputId) => By.XPath($"//div[@id='{inputId}']//div[contains(@class, 'v-input--is-disabled')]");`
The inputId going into it is 'ai-confirm-allergy-modal-reason'. I've tried it as 'input[contains...' and 'contains(@disabled, 'disabled'...' among other things, but my xpath knowledge isn't great yet!
CodePudding user response:
Use below code
String value = driver.findElement(By.XPath("//input[contains(@id, 'ai-confirm-allergy')]").getAttribute("disabled");
Assert.AssertEquals(value, "disabled");
CodePudding user response:
I do not quite get your question. well if you are trying to use xpath to locate an element, you can just use the id; assuming that it is unique.so:
driver.findElement(By.xpath("//input[contains(@id, 'ai-confirm-allergy')]")
should locate the webelement. However, your xpath for the SearchDisabled is locating a div containing class 'v-input--is-disabled' with in another div with id of '{searchId}'; the same logic goes for the next one. your xpath is trying to locate a div containing class 'v-input--is-disabled' which is located with in another div located using input id. I don't think this combination can locate the element highlighted in the picture.