New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document how to test with selenium #603
Comments
A hack, but this seems to work. self.driver.find_element_by_class_name('Select-control').click()
wait = WebDriverWait(self.driver, timeout=10)
wait.until(EC.element_to_be_clickable((By.CLASS_NAME, 'Select-option')))
options = self.driver.find_elements_by_class_name('Select-option')
for option in options:
if option.text == value:
option.click()
break |
I have some Ruby code for this: first("#{element} .Select-input input").set(value)
first("#{element} .Select-option").click Setting the input's value will populate the component with the options that match that name. Then it's just a matter of clicking on that first option. |
Here's what we settled on for poltergeist/phantomJS. The trick is the keypresses need to be "sent" for it to work - can't just "set" the value of the hidden field. within(select_container_element) do
find(".Select").click
find(".Select").native.send_key(desired_option)
find(".Select-option", text: desired_option).click
end |
In C#/Seleno I had to do the following to get it to work: public void SetSelectText(string optionText) {
var select = Find.Element(By.CssSelector(".Select"));
select.Click();
var options = Find.Elements(By.CssSelector(".Select-option")).ToList();
options.ToList().Single(o => o.Text == optionText).Click();
} That is with react-select@0.8.2, didn't bother with trying to get any later version to work. At least some response whether this is prioritized or not would be nice. |
I can't seem to get anything working with NightwatchJS. |
The following works for me: In the IDE:
And the Java translation:
https://groups.google.com/forum/#!topic/selenium-users/FWsu_r7bbr0 |
Hey, I faced the same issue, here is my solution for the Nightwatch by creating a custom command. The DOM I am manipulating in the script might have to be updated.
In fact the select is activated on the MouseDown event, here we trigger the event by injecting some code when testing the website. @etburke I hope it can help you, let me know if it does what you are expecting. |
For those of you trying to work with nightwatch and multiselect, I was able to get this to work with multi select using:
|
I've came up with a custom command for NightwatchJS which worked for me: exports.command = function(selector, data) {
var select = selector + ' .Select .Select-control';
var item = selector + ' .Select .Select-menu .Select-option';
var self = this;
return this
.waitForElementVisible(select, 1000)
.click(select)
.waitForElementVisible(item, 1000, function() {
self.executeAsync(
function() {
var item = arguments[0][0];
var data = arguments[0][1];
var parent = arguments[0][2];
var multi = Array.isArray(data);
if(!multi) {
data = [data];
} else {
// Close the dropdown after a second when all events are hopefully dispatched
setTimeout(() => document.querySelector(parent + ' .Select-input input').blur(), 1000);
}
data.forEach((label) => {
var option = Array.prototype.find.call(
document.querySelectorAll(item),
(e) => label == e.innerHTML
);
option.dispatchEvent(new MouseEvent('mousedown', {bubbles: true}));
});
},
[[item, data, select]] // Pack params into an array, as Selenium works correct with a single parameter only
);
}).waitForElementNotPresent(item, 4000);
}; and the respective test module.exports = {
'Select Tasmania': function(browser) {
var states = '#example .section';
browser
.url('https://jedwatson.github.io/react-select/')
.setReactSelect(states, 'Tasmania')
.waitForElementVisible('div.Select-value.State-Tas', 5000)
.end();
},
'Select Chocolate and Peppermint': function(browser) {
var root = '#example .section:nth-child(2)';
browser
.url('https://jedwatson.github.io/react-select/')
.setReactSelect(root, ['Peppermint', 'Chocolate'])
.waitForElementPresent(root + ' span.Select-value-icon', 5000) // Just assume any value is there
.end();
}
} Hope this helps someone. |
This one worked for me:
|
Hi @oren how to handle next field with your selenium IDE command? |
What @radar proposed also works nicely in nightwatch alike syntax:
|
Has anyone got an example for selenium webdriver in java please? |
@PashminaT
|
@Roscian1Frank - your example worked for my team. Thanks! |
Command: sendKeys This works for me |
@Roscian1Frank could you make it work with latest versions? I cannot find a way to trigger click in the select and open the dropdown with webdriver |
Hi @pietrofxq, My above example is still working for me on Selenium V3.14.0. |
what does (clientName) in the code signify? if (option.getText().equalsIgnoreCase(clientName)){ |
@Vyshnavi-N |
For anyone using nightwatch and the chrome driver, this is what worked for me (custom command):
|
Please reserve the GitHub issue tracker for bugs and feature requests. StackOverflow would be more appropriate for this sort of discussion. |
Why close? This was reported as a documentation bug. Stackoverflow is not really the place for documentation of a custom component. The OP + many others including me wanted the creator of the component to document how it could be tested since automated testing is a first class citizen since many years. Perhaps testing the component also could be made a bit easier. Take a look at the java example above... |
I'm having difficulty selecting an entry using webdriver. I can get as far as clicking on the input, but despite hacks have not yet been able to set the selection. A short guide on how to test this component would be appreciated.
The text was updated successfully, but these errors were encountered: