Reputation:
I'm using Selenium and C#.
I'm trying to find an element id for an input field by the already typed in text (the elements id is autogenerated randomly for every instance) and then type a new text.
My failed attempt:
public void SetValues(){
var textField = driver.FindElement(By.XPath("//input[contains(text(),'my_text')]"));
((IJavaScriptExecutor)driver)
.ExecuteScript("window.scroll(" + textField.Location.X + "," + (textField.Location.Y - 200) + ");");
textField.sendKeys("some_text");
}
How can I make my code to work?
Upvotes: 0
Views: 742
Reputation: 7401
Place holder is an html attribute so you can use @placeholder
, check the following line:
var textField = driver.FindElement(By.XPath("//input[@placeholder='my_placeholder']"));
Edited: There is no way to get the text entered manually if javascript assigns the value to an attribute.
Upvotes: 2