Reputation: 635
I'm kinda new to selenium, and I'm stuck at figuring out one problem: I have an input that's inside this html block and my task is locate it and send keys. The problem is that not only the id is dynamic, but also css selector and Xpath
It all looks like this
Xpath //*[@id="qf_25239c53-8f51-a9af-adff-fb4c61c369dd"]
CSSselector # qf_6fc767f5-f6d9-ce40-dc78-df0e43f6dc75
<label data-v-1a920554="" for="qf_b75b7021-5df4-2283-1c79-23bddcde3a3d" class="q-field row no-wrap items-start indent q-input q-field--outlined q-field--dense">
<div class="q-field__inner relative-position col self-stretch column justify-center">
<div tabindex="-1" class="q-field__control relative-position row no-wrap">
<div class="q-field__control-container col relative-position row no-wrap q-anchor--skip">
<input tabindex="0" placeholder="Заголовок" id="qf_b75b7021-5df4-2283-1c79-23bddcde3a3d" type="text" class="q-field__native q-placeholder"></div></div></div></label>
I solved no such element exception by doing this
IWebElement MarkerNameInput = Setup.Driver.FindElement(By.XPath("(//*[@class = 'q-field__native q-placeholder'])[1]"));
But it had only fixed one exception with another and now I'm stuck at:
InvalidSelectorException: invalid selector: An invalid or illegal selector was specified
So the question is what is the correct way to locate input, so I can send keys inside of it?
Upvotes: 1
Views: 186
Reputation: 193108
The desired element is a dynamic element so to invoke SendKeys()
you have to induce WebDriverWait with ExpectedConditions as ElementToBeClickable Method (By) and you can use either of the following solutions:
CssSelector
:
new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("input.q-field__native.q-placeholder[id^='qf_'][placeholder='Заголовок']"))).SendKeys("Vladimir Krygin");
XPath
:
new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//input[@class='q-field__native q-placeholder' and starts-with(@id, 'qf_')][@placeholder='Заголовок']"))).SendKeys("Vladimir Krygin");
Upvotes: 2
Reputation: 1184
Try following as css selector please :
input.q-field__native.q-placeholder
Upvotes: 0