I'm trying to select a specific value of selectbox using javascript. I planned to use jQuery to select an element, but somehow the site I'm trying to automate blocked it or not using jQuery.
So, I slected an element using document.querySelector();
.
Like below.
document.querySelector("#softBoardListLayer > div:nth-of-type(2) > div:nth-of-type(1) > table > tbody > tr:nth-of-type(1) > td > select").selectedIndex = 01;
It does work. After running this javascript, Seleectbox shows the value I selected using this command.
but when I hit confirm button at the bottom of the website to go to the next page, website says that I haven't selected anything.
here is the selectbox part of html.
<select data-v-f6ebec28="" name="" id="">
<option data-v-f6ebec28="" value="">Select...</option>
<option data-v-f6ebec28="" value="01">Seoul</option>
<option data-v-f6ebec28="" value="02">Busan</option>
<option data-v-f6ebec28="" value="03">Jeju</option>
</select>
Is there any way to select the value of selectbox properly?
you have to very small changes in your HTML code.
first, you have to set the id of the select tag.
then, you have to put that id in
document.querySelector("#select-option")
statement.