javascript - changing the value of a select box by only having the xpath -


i using robotium record load of actions in android web view. there known bug in robotium doesnt let change value of select box. in order combat when test running creating javascript injection change it. works name , id needs able use xpath in case name or id arent available.

at moment can using name , id of select box using:

selectbox = document.getelementbyid(identifyingvalue);

or

selectbox = document.getelementbyname(identifyingvalue);

after can create method change value of select box value want. issue cannot id or name of select box , there isn't similar method via xpath ie:

selectbox = document.getelementbyxpath(identifyingvalue);

my code looks this:

var selectbox; var identifyingattribute = ('$identifyingattribute'); var identifyingvalue = ('$identifyingvalue'); var selectedindex = '$selectedindex'; if (identifyingattribute === 'id') {     selectbox = document.getelementbyid(identifyingvalue); } else if (identifyingattribute === 'name') {     selectbox = document.getelementbyname(identifyingvalue); } else if (identifyingattribute === 'xpath') {     selectbox = document.getelementbyxpath(identifyingvalue);    } selectbox.selectedindex = selectedindex; if (selectbox.onchange) {     selectbox.onchange(); } 

so far can see trying use id , name first , xpath last resort.

is away can select element xpath , change value or perform similar action. or input appreciated.

you can use document.queryselector() , select property css selector.

documentation can found here: https://developer.mozilla.org/en-us/docs/web/api/document.queryselector


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -