elem_set_value {selenider} | R Documentation |
Set the value of an input
Description
elem_set_value()
sets the value of an HTML input element to a string.
Usage
elem_set_value(x, text, timeout = NULL)
elem_send_keys(x, ..., modifiers = NULL, timeout = NULL)
elem_clear_value(x, timeout = NULL)
Arguments
x |
A |
text |
A string to set the value of the input element to. |
timeout |
How long to wait for the element to exist. |
... |
A set of inputs to send to |
modifiers |
A character vector; one or more of "shift", "ctrl"/"control", "alt", and "command"/meta". Note that when using chromote as a backend, these do not work on Mac OS. |
Details
elem_send_keys()
sends a set of inputs to an element.
elem_clear_value()
sets the value of an HTML element to ""
, removing any
existing content.
Value
x
, invisibly.
See Also
Other actions:
elem_click()
,
elem_hover()
,
elem_scroll_to()
,
elem_select()
,
elem_submit()
Examples
html <- "
<input
type='text'
oninput='recordChange(event)'
onkeypress='return checkEnter(event);'
/>
<p></p>
"
js <- "
function recordChange(e) {
document.getElementsByTagName('p').item(0).innerText = e.target.value;
}
function checkEnter(e) {
// If the key pressed was Enter
if (e.keyCode == 13) {
document.getElementsByTagName('p').item(0).innerText = 'Enter pressed!';
return false;
}
return true;
}
"
session <- minimal_selenider_session(html, js = js)
elem_expect(s("p"), has_exact_text(""))
input <- s("input")
elem_set_value(input, "my text")
elem_expect(s("p"), has_text("my text"))
elem_clear_value(input)
elem_expect(s("p"), has_exact_text(""))
elem_send_keys(input, keys$enter)
elem_expect(s("p"), has_text("Enter pressed!"))