Not able to chain element and select by text after upgrading to 0.11.0 from 0.10.0
Hi,
Previously on Splinter 0.10.0 I was able to do: browser.find_by_css('element_css_id').select_by_text('text') and the above used to select text for that css_id but I noticed after upgrade this does not work as expected. Now, it just selects the first text it finds completely ignoring the element_id.
<select id="cooid" name="countryOfOrigin.id" style="width: 140px" >
<option value="null"></option>
<option value="41" >Austria</option>
<option value="42" >Azerbaijan</option>
<option value="43" >Belgium</option>
<option value="9" >Bulgaria</option>
</select><br/>
For the above I want to select by country name like 'Belgium' and before I was able to do
browser.find_by_css('#cooid').select_by_text('Belgium')
but this does not work anymore.
Also this page has lots of Country drop down field so after upgrade it is just selecting the country from the first drop down rather than the specific css_id that is provided.
@Shilpi85 @andrewsmedina
#686 Is what changed this behaviour.
WebDriverElement.select_by_text currently searches from the root of the document, explaining the issue.
If we replace WebDriverElement.select with something like the following (untested):
def select(self, text=None, value=None):
finder = None
if text:
finder = 'text()'
elif value:
finder = '@value'
self.find_by_xpath(
'./option[{}="{}"]'.format(finder, text)
)._element.click()
I think that would get most appropriate behaviour.