0
<select name="s" id="s">
    <option value="64752">Small</option>
    <option value="64753">Medium</option>
</select>

Here is the HTML code for the select type from the website

.realClick('select#s', {x: 1, y: 1})
.insert('input#s', size)

Here is part of my coding I have tried, I get the error "cannot find element: "select#s"

I am not really sure what else to try I am fairly new to automating. I use PhantomJS with real-click PhantomJS. Any ideas would be great. Thank you

2
  • Is the page you're trying to automate publicly available? It's possible the element isn't loaded before you attempt to manipulate the form Commented May 27, 2019 at 6:13
  • @dannybuonocore Yeah it is but I added in wait times so it would pretty much ensure it’s loaded fully plus there’s different buttons on the page that I was able to click but they were just attributes instead of a select Commented May 27, 2019 at 6:15

1 Answer 1

2

I don't think you can use click on selects. I remember when I was using PhantomJS a lot I had to set the selected index of the option I was trying to choose:

page.evaluate(function() {

  // Set the selected index
  var select = document.getElementById('s');
  select.selectedIndex = 1;

  // Trigger a change event
  var onChange = document.createEvent('HTMLEvents');
  onChange.initEvent('change', false, true);
  select.dispatchEvent(onChange);

});

This should select the option Medium.

More info regarding the onChange parameters.

Sign up to request clarification or add additional context in comments.

2 Comments

if there were a size large what would you change to select large?
You're asking if you wanted to select Large from the options? If it's the third option then choose 2 (indices start at 0)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.