Selenium DeselectAll not working for HTML SELECT with multiple attribute





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I am using this HTML code:



<select name="cars" multiple>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>


Manually I select some items. Then I want to deselect all of them (I am using C# but that does not matter):



var carsElement = BrowserDriver.FindElementByName("cars");
var carsSelect = new SelectElement(carsElement);
carsSelect.DeselectAll();


What happens: The first selected options stays selected, others are unselected.



Looking at the code this is what must happen, because DeselectAll() calls Click() for all selected options. You can try that in your browser. This will never unselect all options (unless you hold CTRL while clicking but that is not done by the Selenium code). So the correct way would be to change DeselectAll to press CTRL while clicking as demonstrated by How to perform Control key down in selenium webdriver?



Bottom line, I know how to fix this; my questions are: Am I missing anything? Is there an easier way? Is SelectElement not intended from HTML SELECT multiple?










share|improve this question































    1















    I am using this HTML code:



    <select name="cars" multiple>
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
    <option value="opel">Opel</option>
    <option value="audi">Audi</option>
    </select>


    Manually I select some items. Then I want to deselect all of them (I am using C# but that does not matter):



    var carsElement = BrowserDriver.FindElementByName("cars");
    var carsSelect = new SelectElement(carsElement);
    carsSelect.DeselectAll();


    What happens: The first selected options stays selected, others are unselected.



    Looking at the code this is what must happen, because DeselectAll() calls Click() for all selected options. You can try that in your browser. This will never unselect all options (unless you hold CTRL while clicking but that is not done by the Selenium code). So the correct way would be to change DeselectAll to press CTRL while clicking as demonstrated by How to perform Control key down in selenium webdriver?



    Bottom line, I know how to fix this; my questions are: Am I missing anything? Is there an easier way? Is SelectElement not intended from HTML SELECT multiple?










    share|improve this question



























      1












      1








      1








      I am using this HTML code:



      <select name="cars" multiple>
      <option value="volvo">Volvo</option>
      <option value="saab">Saab</option>
      <option value="opel">Opel</option>
      <option value="audi">Audi</option>
      </select>


      Manually I select some items. Then I want to deselect all of them (I am using C# but that does not matter):



      var carsElement = BrowserDriver.FindElementByName("cars");
      var carsSelect = new SelectElement(carsElement);
      carsSelect.DeselectAll();


      What happens: The first selected options stays selected, others are unselected.



      Looking at the code this is what must happen, because DeselectAll() calls Click() for all selected options. You can try that in your browser. This will never unselect all options (unless you hold CTRL while clicking but that is not done by the Selenium code). So the correct way would be to change DeselectAll to press CTRL while clicking as demonstrated by How to perform Control key down in selenium webdriver?



      Bottom line, I know how to fix this; my questions are: Am I missing anything? Is there an easier way? Is SelectElement not intended from HTML SELECT multiple?










      share|improve this question
















      I am using this HTML code:



      <select name="cars" multiple>
      <option value="volvo">Volvo</option>
      <option value="saab">Saab</option>
      <option value="opel">Opel</option>
      <option value="audi">Audi</option>
      </select>


      Manually I select some items. Then I want to deselect all of them (I am using C# but that does not matter):



      var carsElement = BrowserDriver.FindElementByName("cars");
      var carsSelect = new SelectElement(carsElement);
      carsSelect.DeselectAll();


      What happens: The first selected options stays selected, others are unselected.



      Looking at the code this is what must happen, because DeselectAll() calls Click() for all selected options. You can try that in your browser. This will never unselect all options (unless you hold CTRL while clicking but that is not done by the Selenium code). So the correct way would be to change DeselectAll to press CTRL while clicking as demonstrated by How to perform Control key down in selenium webdriver?



      Bottom line, I know how to fix this; my questions are: Am I missing anything? Is there an easier way? Is SelectElement not intended from HTML SELECT multiple?







      selenium select selenium-webdriver webdriver multi-select






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 '18 at 10:13









      DebanjanB

      47.4k134890




      47.4k134890










      asked Nov 22 '18 at 9:38









      Jack MillerJack Miller

      1,85811932




      1,85811932
























          4 Answers
          4






          active

          oldest

          votes


















          0














          Select class can handle multiple choice dropdown. It even checks if the dropdown is multiple choice when using DeselectAll(). From github



          public void DeselectAll()
          {
          if (!this.IsMultiple)
          {
          throw new InvalidOperationException("You may only deselect all options if multi-select is supported");
          }

          foreach (IWebElement option in this.Options)
          {
          SetSelected(option, false);
          }
          }

          private static void SetSelected(IWebElement option, bool select)
          {
          bool isSelected = option.Selected;
          if ((!isSelected && select) || (isSelected && !select))
          {
          option.Click();
          }
          }


          When you click on the first select option without pressing the control key this option remains selected but all the other options are being deselected, so the click is actually not performed on the rest of the options since both isSelected and select are false in SetSelected.



          The solution is either implement your own DeselectAll() as suggested in your question, or select the first option from the dropdown (which will automatically deselect all the other options) and then deselect this option using control.






          share|improve this answer
























          • So DeselectAll() indeed does not deselect all. But it should according to the method name and the documentation: "Clear all selected entries."

            – Jack Miller
            Nov 22 '18 at 10:22













          • @JackMiller Yes, it should. I used it before without problem but the dropdown was different, the options where visible only after clicking the dropdown and it wasn't necessary to hold ctrl for multiple choice. Maybe that's the problem.

            – Guy
            Nov 22 '18 at 11:24



















          2














          You can for sure deselect these with



          browser.execute_script("[...document.querySelectorAll('[name=cars] option')].map(o => o.selected = false)")





          share|improve this answer

































            0














            Even though I did not ask for code how to set the selection state, I'll post it anyways for anybody who encountered the same problem. This is C# code. You'll need NuGet packages Selenium.WebDriver and Selenium.Support. BrowserDriver is a member variable of my helper class which contains this method.



            /// <summary>
            /// Sets the selection state of <paramref name="selectElement"/>. All options specified by <paramref name="selectedOptions"/>
            /// are select, all others are unselected.
            /// </summary>
            /// <param name="selectElement">HTML select element</param>
            /// <param name="selectedOptions">options to be selected</param>
            internal void SelectStateByText(OpenQA.Selenium.Support.UI.SelectElement selectElement, params string selectedOptions)
            {
            Assert.IsNotNull(selectElement);
            Assert.IsNotNull(selectedOptions);
            CollectionAssert.IsSubsetOf(selectedOptions, selectElement.Options.Select(o => o.Text).ToArray());
            if (!selectElement.IsMultiple)
            {
            Assert.AreEqual(1, selectedOptions.Length);
            selectElement.SelectByText(selectedOptions[0]);
            }
            else
            {
            var actions = new OpenQA.Selenium.Interactions.Actions(BrowserDriver);
            actions.KeyDown(Keys.LeftControl);
            foreach (var option in selectElement.Options)
            {
            if (selectedOptions.Contains(option.Text) && !option.Selected)
            {
            actions.Click(option);
            }
            else if (option.Selected)
            {
            actions.Click(option);
            }
            }
            actions.KeyUp(Keys.LeftControl).Build().Perform();
            }
            }





            share|improve this answer































              -1














              I have verified your usecase of using the deselect_all() method through the Selenium Python Client and it seems to work perfecto.



              deselect_all()



              deselect_all() method clears all selected entries. This is only valid when the SELECT supports multiple selections. throws NotImplementedError If the SELECT does not support multiple selections.





              Illustration



              Note: As you have mentioned in your question I have also simulated the selection of all the items manually





              • Code Block:



                from selenium import webdriver
                from selenium.webdriver.common.by import By
                from selenium.webdriver.support.ui import WebDriverWait
                from selenium.webdriver.support import expected_conditions as EC
                from selenium.webdriver.support.ui import Select
                import time

                options = webdriver.ChromeOptions()
                options.add_argument("start-maximized")
                options.add_argument('disable-infobars')
                driver=webdriver.Chrome(chrome_options=options, executable_path=r'C:UtilityBrowserDriverschromedriver.exe')
                driver.get('https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select_multiple')
                WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.ID,"iframeResult")))
                select_cars = Select(driver.find_element_by_css_selector("select[name='cars']"))
                time.sleep(5) # Timeframe to Manually select all the items
                select_cars.deselect_all()


              • Browser Snapshot:



              deselect_all.gif






              share|improve this answer


























              • Very interesting! In the Python code I see that the same things happens: .Click() of the element(s) is called. Is it possible that you call your Python script using a shortcut which includes CTRL?

                – Jack Miller
                Nov 22 '18 at 11:22












              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53427859%2fselenium-deselectall-not-working-for-html-select-with-multiple-attribute%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              4 Answers
              4






              active

              oldest

              votes








              4 Answers
              4






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              Select class can handle multiple choice dropdown. It even checks if the dropdown is multiple choice when using DeselectAll(). From github



              public void DeselectAll()
              {
              if (!this.IsMultiple)
              {
              throw new InvalidOperationException("You may only deselect all options if multi-select is supported");
              }

              foreach (IWebElement option in this.Options)
              {
              SetSelected(option, false);
              }
              }

              private static void SetSelected(IWebElement option, bool select)
              {
              bool isSelected = option.Selected;
              if ((!isSelected && select) || (isSelected && !select))
              {
              option.Click();
              }
              }


              When you click on the first select option without pressing the control key this option remains selected but all the other options are being deselected, so the click is actually not performed on the rest of the options since both isSelected and select are false in SetSelected.



              The solution is either implement your own DeselectAll() as suggested in your question, or select the first option from the dropdown (which will automatically deselect all the other options) and then deselect this option using control.






              share|improve this answer
























              • So DeselectAll() indeed does not deselect all. But it should according to the method name and the documentation: "Clear all selected entries."

                – Jack Miller
                Nov 22 '18 at 10:22













              • @JackMiller Yes, it should. I used it before without problem but the dropdown was different, the options where visible only after clicking the dropdown and it wasn't necessary to hold ctrl for multiple choice. Maybe that's the problem.

                – Guy
                Nov 22 '18 at 11:24
















              0














              Select class can handle multiple choice dropdown. It even checks if the dropdown is multiple choice when using DeselectAll(). From github



              public void DeselectAll()
              {
              if (!this.IsMultiple)
              {
              throw new InvalidOperationException("You may only deselect all options if multi-select is supported");
              }

              foreach (IWebElement option in this.Options)
              {
              SetSelected(option, false);
              }
              }

              private static void SetSelected(IWebElement option, bool select)
              {
              bool isSelected = option.Selected;
              if ((!isSelected && select) || (isSelected && !select))
              {
              option.Click();
              }
              }


              When you click on the first select option without pressing the control key this option remains selected but all the other options are being deselected, so the click is actually not performed on the rest of the options since both isSelected and select are false in SetSelected.



              The solution is either implement your own DeselectAll() as suggested in your question, or select the first option from the dropdown (which will automatically deselect all the other options) and then deselect this option using control.






              share|improve this answer
























              • So DeselectAll() indeed does not deselect all. But it should according to the method name and the documentation: "Clear all selected entries."

                – Jack Miller
                Nov 22 '18 at 10:22













              • @JackMiller Yes, it should. I used it before without problem but the dropdown was different, the options where visible only after clicking the dropdown and it wasn't necessary to hold ctrl for multiple choice. Maybe that's the problem.

                – Guy
                Nov 22 '18 at 11:24














              0












              0








              0







              Select class can handle multiple choice dropdown. It even checks if the dropdown is multiple choice when using DeselectAll(). From github



              public void DeselectAll()
              {
              if (!this.IsMultiple)
              {
              throw new InvalidOperationException("You may only deselect all options if multi-select is supported");
              }

              foreach (IWebElement option in this.Options)
              {
              SetSelected(option, false);
              }
              }

              private static void SetSelected(IWebElement option, bool select)
              {
              bool isSelected = option.Selected;
              if ((!isSelected && select) || (isSelected && !select))
              {
              option.Click();
              }
              }


              When you click on the first select option without pressing the control key this option remains selected but all the other options are being deselected, so the click is actually not performed on the rest of the options since both isSelected and select are false in SetSelected.



              The solution is either implement your own DeselectAll() as suggested in your question, or select the first option from the dropdown (which will automatically deselect all the other options) and then deselect this option using control.






              share|improve this answer













              Select class can handle multiple choice dropdown. It even checks if the dropdown is multiple choice when using DeselectAll(). From github



              public void DeselectAll()
              {
              if (!this.IsMultiple)
              {
              throw new InvalidOperationException("You may only deselect all options if multi-select is supported");
              }

              foreach (IWebElement option in this.Options)
              {
              SetSelected(option, false);
              }
              }

              private static void SetSelected(IWebElement option, bool select)
              {
              bool isSelected = option.Selected;
              if ((!isSelected && select) || (isSelected && !select))
              {
              option.Click();
              }
              }


              When you click on the first select option without pressing the control key this option remains selected but all the other options are being deselected, so the click is actually not performed on the rest of the options since both isSelected and select are false in SetSelected.



              The solution is either implement your own DeselectAll() as suggested in your question, or select the first option from the dropdown (which will automatically deselect all the other options) and then deselect this option using control.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 22 '18 at 10:13









              GuyGuy

              19.7k72251




              19.7k72251













              • So DeselectAll() indeed does not deselect all. But it should according to the method name and the documentation: "Clear all selected entries."

                – Jack Miller
                Nov 22 '18 at 10:22













              • @JackMiller Yes, it should. I used it before without problem but the dropdown was different, the options where visible only after clicking the dropdown and it wasn't necessary to hold ctrl for multiple choice. Maybe that's the problem.

                – Guy
                Nov 22 '18 at 11:24



















              • So DeselectAll() indeed does not deselect all. But it should according to the method name and the documentation: "Clear all selected entries."

                – Jack Miller
                Nov 22 '18 at 10:22













              • @JackMiller Yes, it should. I used it before without problem but the dropdown was different, the options where visible only after clicking the dropdown and it wasn't necessary to hold ctrl for multiple choice. Maybe that's the problem.

                – Guy
                Nov 22 '18 at 11:24

















              So DeselectAll() indeed does not deselect all. But it should according to the method name and the documentation: "Clear all selected entries."

              – Jack Miller
              Nov 22 '18 at 10:22







              So DeselectAll() indeed does not deselect all. But it should according to the method name and the documentation: "Clear all selected entries."

              – Jack Miller
              Nov 22 '18 at 10:22















              @JackMiller Yes, it should. I used it before without problem but the dropdown was different, the options where visible only after clicking the dropdown and it wasn't necessary to hold ctrl for multiple choice. Maybe that's the problem.

              – Guy
              Nov 22 '18 at 11:24





              @JackMiller Yes, it should. I used it before without problem but the dropdown was different, the options where visible only after clicking the dropdown and it wasn't necessary to hold ctrl for multiple choice. Maybe that's the problem.

              – Guy
              Nov 22 '18 at 11:24













              2














              You can for sure deselect these with



              browser.execute_script("[...document.querySelectorAll('[name=cars] option')].map(o => o.selected = false)")





              share|improve this answer






























                2














                You can for sure deselect these with



                browser.execute_script("[...document.querySelectorAll('[name=cars] option')].map(o => o.selected = false)")





                share|improve this answer




























                  2












                  2








                  2







                  You can for sure deselect these with



                  browser.execute_script("[...document.querySelectorAll('[name=cars] option')].map(o => o.selected = false)")





                  share|improve this answer















                  You can for sure deselect these with



                  browser.execute_script("[...document.querySelectorAll('[name=cars] option')].map(o => o.selected = false)")






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 22 '18 at 12:27

























                  answered Nov 22 '18 at 9:56









                  pguardiariopguardiario

                  37k1080118




                  37k1080118























                      0














                      Even though I did not ask for code how to set the selection state, I'll post it anyways for anybody who encountered the same problem. This is C# code. You'll need NuGet packages Selenium.WebDriver and Selenium.Support. BrowserDriver is a member variable of my helper class which contains this method.



                      /// <summary>
                      /// Sets the selection state of <paramref name="selectElement"/>. All options specified by <paramref name="selectedOptions"/>
                      /// are select, all others are unselected.
                      /// </summary>
                      /// <param name="selectElement">HTML select element</param>
                      /// <param name="selectedOptions">options to be selected</param>
                      internal void SelectStateByText(OpenQA.Selenium.Support.UI.SelectElement selectElement, params string selectedOptions)
                      {
                      Assert.IsNotNull(selectElement);
                      Assert.IsNotNull(selectedOptions);
                      CollectionAssert.IsSubsetOf(selectedOptions, selectElement.Options.Select(o => o.Text).ToArray());
                      if (!selectElement.IsMultiple)
                      {
                      Assert.AreEqual(1, selectedOptions.Length);
                      selectElement.SelectByText(selectedOptions[0]);
                      }
                      else
                      {
                      var actions = new OpenQA.Selenium.Interactions.Actions(BrowserDriver);
                      actions.KeyDown(Keys.LeftControl);
                      foreach (var option in selectElement.Options)
                      {
                      if (selectedOptions.Contains(option.Text) && !option.Selected)
                      {
                      actions.Click(option);
                      }
                      else if (option.Selected)
                      {
                      actions.Click(option);
                      }
                      }
                      actions.KeyUp(Keys.LeftControl).Build().Perform();
                      }
                      }





                      share|improve this answer




























                        0














                        Even though I did not ask for code how to set the selection state, I'll post it anyways for anybody who encountered the same problem. This is C# code. You'll need NuGet packages Selenium.WebDriver and Selenium.Support. BrowserDriver is a member variable of my helper class which contains this method.



                        /// <summary>
                        /// Sets the selection state of <paramref name="selectElement"/>. All options specified by <paramref name="selectedOptions"/>
                        /// are select, all others are unselected.
                        /// </summary>
                        /// <param name="selectElement">HTML select element</param>
                        /// <param name="selectedOptions">options to be selected</param>
                        internal void SelectStateByText(OpenQA.Selenium.Support.UI.SelectElement selectElement, params string selectedOptions)
                        {
                        Assert.IsNotNull(selectElement);
                        Assert.IsNotNull(selectedOptions);
                        CollectionAssert.IsSubsetOf(selectedOptions, selectElement.Options.Select(o => o.Text).ToArray());
                        if (!selectElement.IsMultiple)
                        {
                        Assert.AreEqual(1, selectedOptions.Length);
                        selectElement.SelectByText(selectedOptions[0]);
                        }
                        else
                        {
                        var actions = new OpenQA.Selenium.Interactions.Actions(BrowserDriver);
                        actions.KeyDown(Keys.LeftControl);
                        foreach (var option in selectElement.Options)
                        {
                        if (selectedOptions.Contains(option.Text) && !option.Selected)
                        {
                        actions.Click(option);
                        }
                        else if (option.Selected)
                        {
                        actions.Click(option);
                        }
                        }
                        actions.KeyUp(Keys.LeftControl).Build().Perform();
                        }
                        }





                        share|improve this answer


























                          0












                          0








                          0







                          Even though I did not ask for code how to set the selection state, I'll post it anyways for anybody who encountered the same problem. This is C# code. You'll need NuGet packages Selenium.WebDriver and Selenium.Support. BrowserDriver is a member variable of my helper class which contains this method.



                          /// <summary>
                          /// Sets the selection state of <paramref name="selectElement"/>. All options specified by <paramref name="selectedOptions"/>
                          /// are select, all others are unselected.
                          /// </summary>
                          /// <param name="selectElement">HTML select element</param>
                          /// <param name="selectedOptions">options to be selected</param>
                          internal void SelectStateByText(OpenQA.Selenium.Support.UI.SelectElement selectElement, params string selectedOptions)
                          {
                          Assert.IsNotNull(selectElement);
                          Assert.IsNotNull(selectedOptions);
                          CollectionAssert.IsSubsetOf(selectedOptions, selectElement.Options.Select(o => o.Text).ToArray());
                          if (!selectElement.IsMultiple)
                          {
                          Assert.AreEqual(1, selectedOptions.Length);
                          selectElement.SelectByText(selectedOptions[0]);
                          }
                          else
                          {
                          var actions = new OpenQA.Selenium.Interactions.Actions(BrowserDriver);
                          actions.KeyDown(Keys.LeftControl);
                          foreach (var option in selectElement.Options)
                          {
                          if (selectedOptions.Contains(option.Text) && !option.Selected)
                          {
                          actions.Click(option);
                          }
                          else if (option.Selected)
                          {
                          actions.Click(option);
                          }
                          }
                          actions.KeyUp(Keys.LeftControl).Build().Perform();
                          }
                          }





                          share|improve this answer













                          Even though I did not ask for code how to set the selection state, I'll post it anyways for anybody who encountered the same problem. This is C# code. You'll need NuGet packages Selenium.WebDriver and Selenium.Support. BrowserDriver is a member variable of my helper class which contains this method.



                          /// <summary>
                          /// Sets the selection state of <paramref name="selectElement"/>. All options specified by <paramref name="selectedOptions"/>
                          /// are select, all others are unselected.
                          /// </summary>
                          /// <param name="selectElement">HTML select element</param>
                          /// <param name="selectedOptions">options to be selected</param>
                          internal void SelectStateByText(OpenQA.Selenium.Support.UI.SelectElement selectElement, params string selectedOptions)
                          {
                          Assert.IsNotNull(selectElement);
                          Assert.IsNotNull(selectedOptions);
                          CollectionAssert.IsSubsetOf(selectedOptions, selectElement.Options.Select(o => o.Text).ToArray());
                          if (!selectElement.IsMultiple)
                          {
                          Assert.AreEqual(1, selectedOptions.Length);
                          selectElement.SelectByText(selectedOptions[0]);
                          }
                          else
                          {
                          var actions = new OpenQA.Selenium.Interactions.Actions(BrowserDriver);
                          actions.KeyDown(Keys.LeftControl);
                          foreach (var option in selectElement.Options)
                          {
                          if (selectedOptions.Contains(option.Text) && !option.Selected)
                          {
                          actions.Click(option);
                          }
                          else if (option.Selected)
                          {
                          actions.Click(option);
                          }
                          }
                          actions.KeyUp(Keys.LeftControl).Build().Perform();
                          }
                          }






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 22 '18 at 10:17









                          Jack MillerJack Miller

                          1,85811932




                          1,85811932























                              -1














                              I have verified your usecase of using the deselect_all() method through the Selenium Python Client and it seems to work perfecto.



                              deselect_all()



                              deselect_all() method clears all selected entries. This is only valid when the SELECT supports multiple selections. throws NotImplementedError If the SELECT does not support multiple selections.





                              Illustration



                              Note: As you have mentioned in your question I have also simulated the selection of all the items manually





                              • Code Block:



                                from selenium import webdriver
                                from selenium.webdriver.common.by import By
                                from selenium.webdriver.support.ui import WebDriverWait
                                from selenium.webdriver.support import expected_conditions as EC
                                from selenium.webdriver.support.ui import Select
                                import time

                                options = webdriver.ChromeOptions()
                                options.add_argument("start-maximized")
                                options.add_argument('disable-infobars')
                                driver=webdriver.Chrome(chrome_options=options, executable_path=r'C:UtilityBrowserDriverschromedriver.exe')
                                driver.get('https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select_multiple')
                                WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.ID,"iframeResult")))
                                select_cars = Select(driver.find_element_by_css_selector("select[name='cars']"))
                                time.sleep(5) # Timeframe to Manually select all the items
                                select_cars.deselect_all()


                              • Browser Snapshot:



                              deselect_all.gif






                              share|improve this answer


























                              • Very interesting! In the Python code I see that the same things happens: .Click() of the element(s) is called. Is it possible that you call your Python script using a shortcut which includes CTRL?

                                – Jack Miller
                                Nov 22 '18 at 11:22
















                              -1














                              I have verified your usecase of using the deselect_all() method through the Selenium Python Client and it seems to work perfecto.



                              deselect_all()



                              deselect_all() method clears all selected entries. This is only valid when the SELECT supports multiple selections. throws NotImplementedError If the SELECT does not support multiple selections.





                              Illustration



                              Note: As you have mentioned in your question I have also simulated the selection of all the items manually





                              • Code Block:



                                from selenium import webdriver
                                from selenium.webdriver.common.by import By
                                from selenium.webdriver.support.ui import WebDriverWait
                                from selenium.webdriver.support import expected_conditions as EC
                                from selenium.webdriver.support.ui import Select
                                import time

                                options = webdriver.ChromeOptions()
                                options.add_argument("start-maximized")
                                options.add_argument('disable-infobars')
                                driver=webdriver.Chrome(chrome_options=options, executable_path=r'C:UtilityBrowserDriverschromedriver.exe')
                                driver.get('https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select_multiple')
                                WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.ID,"iframeResult")))
                                select_cars = Select(driver.find_element_by_css_selector("select[name='cars']"))
                                time.sleep(5) # Timeframe to Manually select all the items
                                select_cars.deselect_all()


                              • Browser Snapshot:



                              deselect_all.gif






                              share|improve this answer


























                              • Very interesting! In the Python code I see that the same things happens: .Click() of the element(s) is called. Is it possible that you call your Python script using a shortcut which includes CTRL?

                                – Jack Miller
                                Nov 22 '18 at 11:22














                              -1












                              -1








                              -1







                              I have verified your usecase of using the deselect_all() method through the Selenium Python Client and it seems to work perfecto.



                              deselect_all()



                              deselect_all() method clears all selected entries. This is only valid when the SELECT supports multiple selections. throws NotImplementedError If the SELECT does not support multiple selections.





                              Illustration



                              Note: As you have mentioned in your question I have also simulated the selection of all the items manually





                              • Code Block:



                                from selenium import webdriver
                                from selenium.webdriver.common.by import By
                                from selenium.webdriver.support.ui import WebDriverWait
                                from selenium.webdriver.support import expected_conditions as EC
                                from selenium.webdriver.support.ui import Select
                                import time

                                options = webdriver.ChromeOptions()
                                options.add_argument("start-maximized")
                                options.add_argument('disable-infobars')
                                driver=webdriver.Chrome(chrome_options=options, executable_path=r'C:UtilityBrowserDriverschromedriver.exe')
                                driver.get('https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select_multiple')
                                WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.ID,"iframeResult")))
                                select_cars = Select(driver.find_element_by_css_selector("select[name='cars']"))
                                time.sleep(5) # Timeframe to Manually select all the items
                                select_cars.deselect_all()


                              • Browser Snapshot:



                              deselect_all.gif






                              share|improve this answer















                              I have verified your usecase of using the deselect_all() method through the Selenium Python Client and it seems to work perfecto.



                              deselect_all()



                              deselect_all() method clears all selected entries. This is only valid when the SELECT supports multiple selections. throws NotImplementedError If the SELECT does not support multiple selections.





                              Illustration



                              Note: As you have mentioned in your question I have also simulated the selection of all the items manually





                              • Code Block:



                                from selenium import webdriver
                                from selenium.webdriver.common.by import By
                                from selenium.webdriver.support.ui import WebDriverWait
                                from selenium.webdriver.support import expected_conditions as EC
                                from selenium.webdriver.support.ui import Select
                                import time

                                options = webdriver.ChromeOptions()
                                options.add_argument("start-maximized")
                                options.add_argument('disable-infobars')
                                driver=webdriver.Chrome(chrome_options=options, executable_path=r'C:UtilityBrowserDriverschromedriver.exe')
                                driver.get('https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select_multiple')
                                WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.ID,"iframeResult")))
                                select_cars = Select(driver.find_element_by_css_selector("select[name='cars']"))
                                time.sleep(5) # Timeframe to Manually select all the items
                                select_cars.deselect_all()


                              • Browser Snapshot:



                              deselect_all.gif







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Nov 22 '18 at 10:40

























                              answered Nov 22 '18 at 10:35









                              DebanjanBDebanjanB

                              47.4k134890




                              47.4k134890













                              • Very interesting! In the Python code I see that the same things happens: .Click() of the element(s) is called. Is it possible that you call your Python script using a shortcut which includes CTRL?

                                – Jack Miller
                                Nov 22 '18 at 11:22



















                              • Very interesting! In the Python code I see that the same things happens: .Click() of the element(s) is called. Is it possible that you call your Python script using a shortcut which includes CTRL?

                                – Jack Miller
                                Nov 22 '18 at 11:22

















                              Very interesting! In the Python code I see that the same things happens: .Click() of the element(s) is called. Is it possible that you call your Python script using a shortcut which includes CTRL?

                              – Jack Miller
                              Nov 22 '18 at 11:22





                              Very interesting! In the Python code I see that the same things happens: .Click() of the element(s) is called. Is it possible that you call your Python script using a shortcut which includes CTRL?

                              – Jack Miller
                              Nov 22 '18 at 11:22


















                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53427859%2fselenium-deselectall-not-working-for-html-select-with-multiple-attribute%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              鏡平學校

                              ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

                              Why https connections are so slow when debugging (stepping over) in Java?