Python 3. Selenium - how to use multiple conditions with find_element_by_xpath












0














I can't find a solution. The htlm code is as follows :



<select class="SelectEquipe2" name="Equipe2Id">
<option value='2'>AC Ajaccio<option value='3'>GFC Ajaccio<option value='15'>Amiens SC<option value='19'>Angers SCO<option value='30'>...
</select>


The problem is that there is a class="SelectEquipe1" I can't select option value from the second class. I tried the following code on Python 3.



driver.find_element_by_xpath('//select[@class,"SelectEquipe2"]/option[@value="15"]').click()


OR



driver.find_element_by_xpath('//select[contains(@class,"SelectEquipe2") and contains(.,"15")]')


with no success...



do you have any solution?



EDIT :



The actual HTML code :



 <select class="SelectEquipe2" name="Equipe2Id">
<option value='41'selected>AJ Auxerre<option value='47'>SC Bastia<option value='65'>FC Girondins de Bordeaux<option value='76'>Stade Brestois 29<option value='82'>SM Caen<option value='139'>Dijon FCO<option value='177'>EA Guingamp<option value='201'>Istres FC<option value='224'>Havre AC<option value='226'>Le Mans FC<option value='231'>RC Lens<option value='242'>Lille OSC<option value='251'>FC Lorient<option value='258'>Olympique Lyonnais<option value='275'>Olympique de Marseille<option value='285'>FC Metz<option value='290'>AS Monaco FC<option value='299'>Montpellier Hérault SC<option value='308'>AS Nancy Lorraine<option value='310'>FC Nantes<option value='314'>OGC Nice<option value='339'>Paris Saint-Germain FC<option value='373'>Stade de Reims<option value='375'>Stade Rennais FC<option value='398'>AS Saint-Etienne<option value='429'>CS Sedan<option value='439'>FC Sochaux-Montbéliard<option value='442'>RC Strasbourg Alsace<option value='568'>Thonon Évian FC<option value='455'>Toulouse FC<option value='464'>ESTAC Troyes<option value='471'>Valenciennes FC
</select>


I succeed in selecting the option value for the first class "SelectEquipe1" using :



driver.find_element_by_xpath('//select[@class="SelectEquipe1"]').click()
driver.find_element_by_xpath("//option[@value='339']").click()



but this does not work for the 2nd class, it always takes the first class options whereas I want it to take the second one.










share|improve this question
























  • Can you confirm if you have provided the actual HTML within the question or provided a tailor made HTML?
    – DebanjanB
    Nov 23 '18 at 11:31










  • That is the actual HTML from the code source, I did not just put all the option value but that's the structure
    – MFP
    Nov 23 '18 at 12:23
















0














I can't find a solution. The htlm code is as follows :



<select class="SelectEquipe2" name="Equipe2Id">
<option value='2'>AC Ajaccio<option value='3'>GFC Ajaccio<option value='15'>Amiens SC<option value='19'>Angers SCO<option value='30'>...
</select>


The problem is that there is a class="SelectEquipe1" I can't select option value from the second class. I tried the following code on Python 3.



driver.find_element_by_xpath('//select[@class,"SelectEquipe2"]/option[@value="15"]').click()


OR



driver.find_element_by_xpath('//select[contains(@class,"SelectEquipe2") and contains(.,"15")]')


with no success...



do you have any solution?



EDIT :



The actual HTML code :



 <select class="SelectEquipe2" name="Equipe2Id">
<option value='41'selected>AJ Auxerre<option value='47'>SC Bastia<option value='65'>FC Girondins de Bordeaux<option value='76'>Stade Brestois 29<option value='82'>SM Caen<option value='139'>Dijon FCO<option value='177'>EA Guingamp<option value='201'>Istres FC<option value='224'>Havre AC<option value='226'>Le Mans FC<option value='231'>RC Lens<option value='242'>Lille OSC<option value='251'>FC Lorient<option value='258'>Olympique Lyonnais<option value='275'>Olympique de Marseille<option value='285'>FC Metz<option value='290'>AS Monaco FC<option value='299'>Montpellier Hérault SC<option value='308'>AS Nancy Lorraine<option value='310'>FC Nantes<option value='314'>OGC Nice<option value='339'>Paris Saint-Germain FC<option value='373'>Stade de Reims<option value='375'>Stade Rennais FC<option value='398'>AS Saint-Etienne<option value='429'>CS Sedan<option value='439'>FC Sochaux-Montbéliard<option value='442'>RC Strasbourg Alsace<option value='568'>Thonon Évian FC<option value='455'>Toulouse FC<option value='464'>ESTAC Troyes<option value='471'>Valenciennes FC
</select>


I succeed in selecting the option value for the first class "SelectEquipe1" using :



driver.find_element_by_xpath('//select[@class="SelectEquipe1"]').click()
driver.find_element_by_xpath("//option[@value='339']").click()



but this does not work for the 2nd class, it always takes the first class options whereas I want it to take the second one.










share|improve this question
























  • Can you confirm if you have provided the actual HTML within the question or provided a tailor made HTML?
    – DebanjanB
    Nov 23 '18 at 11:31










  • That is the actual HTML from the code source, I did not just put all the option value but that's the structure
    – MFP
    Nov 23 '18 at 12:23














0












0








0







I can't find a solution. The htlm code is as follows :



<select class="SelectEquipe2" name="Equipe2Id">
<option value='2'>AC Ajaccio<option value='3'>GFC Ajaccio<option value='15'>Amiens SC<option value='19'>Angers SCO<option value='30'>...
</select>


The problem is that there is a class="SelectEquipe1" I can't select option value from the second class. I tried the following code on Python 3.



driver.find_element_by_xpath('//select[@class,"SelectEquipe2"]/option[@value="15"]').click()


OR



driver.find_element_by_xpath('//select[contains(@class,"SelectEquipe2") and contains(.,"15")]')


with no success...



do you have any solution?



EDIT :



The actual HTML code :



 <select class="SelectEquipe2" name="Equipe2Id">
<option value='41'selected>AJ Auxerre<option value='47'>SC Bastia<option value='65'>FC Girondins de Bordeaux<option value='76'>Stade Brestois 29<option value='82'>SM Caen<option value='139'>Dijon FCO<option value='177'>EA Guingamp<option value='201'>Istres FC<option value='224'>Havre AC<option value='226'>Le Mans FC<option value='231'>RC Lens<option value='242'>Lille OSC<option value='251'>FC Lorient<option value='258'>Olympique Lyonnais<option value='275'>Olympique de Marseille<option value='285'>FC Metz<option value='290'>AS Monaco FC<option value='299'>Montpellier Hérault SC<option value='308'>AS Nancy Lorraine<option value='310'>FC Nantes<option value='314'>OGC Nice<option value='339'>Paris Saint-Germain FC<option value='373'>Stade de Reims<option value='375'>Stade Rennais FC<option value='398'>AS Saint-Etienne<option value='429'>CS Sedan<option value='439'>FC Sochaux-Montbéliard<option value='442'>RC Strasbourg Alsace<option value='568'>Thonon Évian FC<option value='455'>Toulouse FC<option value='464'>ESTAC Troyes<option value='471'>Valenciennes FC
</select>


I succeed in selecting the option value for the first class "SelectEquipe1" using :



driver.find_element_by_xpath('//select[@class="SelectEquipe1"]').click()
driver.find_element_by_xpath("//option[@value='339']").click()



but this does not work for the 2nd class, it always takes the first class options whereas I want it to take the second one.










share|improve this question















I can't find a solution. The htlm code is as follows :



<select class="SelectEquipe2" name="Equipe2Id">
<option value='2'>AC Ajaccio<option value='3'>GFC Ajaccio<option value='15'>Amiens SC<option value='19'>Angers SCO<option value='30'>...
</select>


The problem is that there is a class="SelectEquipe1" I can't select option value from the second class. I tried the following code on Python 3.



driver.find_element_by_xpath('//select[@class,"SelectEquipe2"]/option[@value="15"]').click()


OR



driver.find_element_by_xpath('//select[contains(@class,"SelectEquipe2") and contains(.,"15")]')


with no success...



do you have any solution?



EDIT :



The actual HTML code :



 <select class="SelectEquipe2" name="Equipe2Id">
<option value='41'selected>AJ Auxerre<option value='47'>SC Bastia<option value='65'>FC Girondins de Bordeaux<option value='76'>Stade Brestois 29<option value='82'>SM Caen<option value='139'>Dijon FCO<option value='177'>EA Guingamp<option value='201'>Istres FC<option value='224'>Havre AC<option value='226'>Le Mans FC<option value='231'>RC Lens<option value='242'>Lille OSC<option value='251'>FC Lorient<option value='258'>Olympique Lyonnais<option value='275'>Olympique de Marseille<option value='285'>FC Metz<option value='290'>AS Monaco FC<option value='299'>Montpellier Hérault SC<option value='308'>AS Nancy Lorraine<option value='310'>FC Nantes<option value='314'>OGC Nice<option value='339'>Paris Saint-Germain FC<option value='373'>Stade de Reims<option value='375'>Stade Rennais FC<option value='398'>AS Saint-Etienne<option value='429'>CS Sedan<option value='439'>FC Sochaux-Montbéliard<option value='442'>RC Strasbourg Alsace<option value='568'>Thonon Évian FC<option value='455'>Toulouse FC<option value='464'>ESTAC Troyes<option value='471'>Valenciennes FC
</select>


I succeed in selecting the option value for the first class "SelectEquipe1" using :



driver.find_element_by_xpath('//select[@class="SelectEquipe1"]').click()
driver.find_element_by_xpath("//option[@value='339']").click()



but this does not work for the 2nd class, it always takes the first class options whereas I want it to take the second one.







python selenium xpath






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 14:59







MFP

















asked Nov 23 '18 at 11:27









MFPMFP

11




11












  • Can you confirm if you have provided the actual HTML within the question or provided a tailor made HTML?
    – DebanjanB
    Nov 23 '18 at 11:31










  • That is the actual HTML from the code source, I did not just put all the option value but that's the structure
    – MFP
    Nov 23 '18 at 12:23


















  • Can you confirm if you have provided the actual HTML within the question or provided a tailor made HTML?
    – DebanjanB
    Nov 23 '18 at 11:31










  • That is the actual HTML from the code source, I did not just put all the option value but that's the structure
    – MFP
    Nov 23 '18 at 12:23
















Can you confirm if you have provided the actual HTML within the question or provided a tailor made HTML?
– DebanjanB
Nov 23 '18 at 11:31




Can you confirm if you have provided the actual HTML within the question or provided a tailor made HTML?
– DebanjanB
Nov 23 '18 at 11:31












That is the actual HTML from the code source, I did not just put all the option value but that's the structure
– MFP
Nov 23 '18 at 12:23




That is the actual HTML from the code source, I did not just put all the option value but that's the structure
– MFP
Nov 23 '18 at 12:23












2 Answers
2






active

oldest

votes


















0














After checking the HTML you have provided. It is clear that there is no closing tag for <option> tags. You will not be able to select the second option unless there is closing </option> tag for the first option.



Your html should look like this.



<select class="SelectEquipe2" name="Equipe2Id">
<option value='2'>AC Ajaccio</option><option value='3'>GFC Ajaccio</option><option value='15'>Amiens SC</option><option value='19'>Angers SCO</option><option value='30'></option>...
</select>


All child nodes must be properly closed






share|improve this answer































    0














    The answer was merely to use :



    driver.find_element_by_xpath("//select[@class='SelectEquipe2']/option[@value='258']").click()


    thank you all






    share|improve this answer





















      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%2f53445854%2fpython-3-selenium-how-to-use-multiple-conditions-with-find-element-by-xpath%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      After checking the HTML you have provided. It is clear that there is no closing tag for <option> tags. You will not be able to select the second option unless there is closing </option> tag for the first option.



      Your html should look like this.



      <select class="SelectEquipe2" name="Equipe2Id">
      <option value='2'>AC Ajaccio</option><option value='3'>GFC Ajaccio</option><option value='15'>Amiens SC</option><option value='19'>Angers SCO</option><option value='30'></option>...
      </select>


      All child nodes must be properly closed






      share|improve this answer




























        0














        After checking the HTML you have provided. It is clear that there is no closing tag for <option> tags. You will not be able to select the second option unless there is closing </option> tag for the first option.



        Your html should look like this.



        <select class="SelectEquipe2" name="Equipe2Id">
        <option value='2'>AC Ajaccio</option><option value='3'>GFC Ajaccio</option><option value='15'>Amiens SC</option><option value='19'>Angers SCO</option><option value='30'></option>...
        </select>


        All child nodes must be properly closed






        share|improve this answer


























          0












          0








          0






          After checking the HTML you have provided. It is clear that there is no closing tag for <option> tags. You will not be able to select the second option unless there is closing </option> tag for the first option.



          Your html should look like this.



          <select class="SelectEquipe2" name="Equipe2Id">
          <option value='2'>AC Ajaccio</option><option value='3'>GFC Ajaccio</option><option value='15'>Amiens SC</option><option value='19'>Angers SCO</option><option value='30'></option>...
          </select>


          All child nodes must be properly closed






          share|improve this answer














          After checking the HTML you have provided. It is clear that there is no closing tag for <option> tags. You will not be able to select the second option unless there is closing </option> tag for the first option.



          Your html should look like this.



          <select class="SelectEquipe2" name="Equipe2Id">
          <option value='2'>AC Ajaccio</option><option value='3'>GFC Ajaccio</option><option value='15'>Amiens SC</option><option value='19'>Angers SCO</option><option value='30'></option>...
          </select>


          All child nodes must be properly closed







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 23 '18 at 12:29

























          answered Nov 23 '18 at 12:24









          Mr EmployeeMr Employee

          12




          12

























              0














              The answer was merely to use :



              driver.find_element_by_xpath("//select[@class='SelectEquipe2']/option[@value='258']").click()


              thank you all






              share|improve this answer


























                0














                The answer was merely to use :



                driver.find_element_by_xpath("//select[@class='SelectEquipe2']/option[@value='258']").click()


                thank you all






                share|improve this answer
























                  0












                  0








                  0






                  The answer was merely to use :



                  driver.find_element_by_xpath("//select[@class='SelectEquipe2']/option[@value='258']").click()


                  thank you all






                  share|improve this answer












                  The answer was merely to use :



                  driver.find_element_by_xpath("//select[@class='SelectEquipe2']/option[@value='258']").click()


                  thank you all







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 25 '18 at 12:29









                  MFPMFP

                  11




                  11






























                      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.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • 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%2f53445854%2fpython-3-selenium-how-to-use-multiple-conditions-with-find-element-by-xpath%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

                      What visual should I use to simply compare current year value vs last year in Power BI desktop

                      How to ignore python UserWarning in pytest?

                      Alexandru Averescu