How to Select an dropdown element with Span tag in Selenium [duplicate]












-2
















This question already has an answer here:




  • Element should have been “select” but was “div” getting an error in selenium

    2 answers




I'm trying to select an option from Dropdown with Span tag in Selenium. Below is my Selenium code



new Select (driver.findElement(By.cssSelector("span.select2-selection.select2-selection--single"))).selectByVisibleText("Prison");


Getting error 'org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was "span"'



HTML Code for the dropdown is as below;



HTML code



Kind request for any help.










share|improve this question















marked as duplicate by DebanjanB selenium
Users with the  selenium badge can single-handedly close selenium questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 2 at 13:41


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 1





    Please don't post pictures of your code. Insert it in a codeblock.

    – ochs.tobi
    Jan 2 at 12:24
















-2
















This question already has an answer here:




  • Element should have been “select” but was “div” getting an error in selenium

    2 answers




I'm trying to select an option from Dropdown with Span tag in Selenium. Below is my Selenium code



new Select (driver.findElement(By.cssSelector("span.select2-selection.select2-selection--single"))).selectByVisibleText("Prison");


Getting error 'org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was "span"'



HTML Code for the dropdown is as below;



HTML code



Kind request for any help.










share|improve this question















marked as duplicate by DebanjanB selenium
Users with the  selenium badge can single-handedly close selenium questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 2 at 13:41


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 1





    Please don't post pictures of your code. Insert it in a codeblock.

    – ochs.tobi
    Jan 2 at 12:24














-2












-2








-2









This question already has an answer here:




  • Element should have been “select” but was “div” getting an error in selenium

    2 answers




I'm trying to select an option from Dropdown with Span tag in Selenium. Below is my Selenium code



new Select (driver.findElement(By.cssSelector("span.select2-selection.select2-selection--single"))).selectByVisibleText("Prison");


Getting error 'org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was "span"'



HTML Code for the dropdown is as below;



HTML code



Kind request for any help.










share|improve this question

















This question already has an answer here:




  • Element should have been “select” but was “div” getting an error in selenium

    2 answers




I'm trying to select an option from Dropdown with Span tag in Selenium. Below is my Selenium code



new Select (driver.findElement(By.cssSelector("span.select2-selection.select2-selection--single"))).selectByVisibleText("Prison");


Getting error 'org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was "span"'



HTML Code for the dropdown is as below;



HTML code



Kind request for any help.





This question already has an answer here:




  • Element should have been “select” but was “div” getting an error in selenium

    2 answers








html selenium






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 12:45









ochs.tobi

1,48471333




1,48471333










asked Jan 2 at 12:19









KaviKavi

11




11




marked as duplicate by DebanjanB selenium
Users with the  selenium badge can single-handedly close selenium questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 2 at 13:41


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by DebanjanB selenium
Users with the  selenium badge can single-handedly close selenium questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 2 at 13:41


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 1





    Please don't post pictures of your code. Insert it in a codeblock.

    – ochs.tobi
    Jan 2 at 12:24














  • 1





    Please don't post pictures of your code. Insert it in a codeblock.

    – ochs.tobi
    Jan 2 at 12:24








1




1





Please don't post pictures of your code. Insert it in a codeblock.

– ochs.tobi
Jan 2 at 12:24





Please don't post pictures of your code. Insert it in a codeblock.

– ochs.tobi
Jan 2 at 12:24












1 Answer
1






active

oldest

votes


















0














you cannot use in select class. Try
Select sel = new Select(driver.findelement(By.id('P37_ACCOMMODATION_STATUS')));
sel.SelectByVisibleText('Prision');






share|improve this answer
































    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    you cannot use in select class. Try
    Select sel = new Select(driver.findelement(By.id('P37_ACCOMMODATION_STATUS')));
    sel.SelectByVisibleText('Prision');






    share|improve this answer






























      0














      you cannot use in select class. Try
      Select sel = new Select(driver.findelement(By.id('P37_ACCOMMODATION_STATUS')));
      sel.SelectByVisibleText('Prision');






      share|improve this answer




























        0












        0








        0







        you cannot use in select class. Try
        Select sel = new Select(driver.findelement(By.id('P37_ACCOMMODATION_STATUS')));
        sel.SelectByVisibleText('Prision');






        share|improve this answer















        you cannot use in select class. Try
        Select sel = new Select(driver.findelement(By.id('P37_ACCOMMODATION_STATUS')));
        sel.SelectByVisibleText('Prision');







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 2 at 13:28

























        answered Jan 2 at 13:20









        NirmalKumarNirmalKumar

        163




        163

















            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

            Npm cannot find a required file even through it is in the searched directory