1

I am trying to click multiple buttons with Selenium ChromeDriver, should be easy, I just find the buttons by class name because they all have the same class name, looping through each one and clicking. However for some reason, if I check the len of the Buttons it is 0 it is like it's not on the page...

Here is the HTML:

button1

<span data-fieldid="9537" id="bounceRatingOrderBtn" name="bounceRatingOrderBtn" class="viewCommand viewSize1 viewCommandGreenBtn" data-columnnum="1" data-showonload="1" data-defaultvalue="" data-isrequired="0" data-personalareaviewposition="manage_area" data-ispersonalareaviewable="1" data-ajax_path="//my.yad2.co.il/newOrder/index.php?action=updateBounceListing&amp;CatID=3&amp;SubCatID=0&amp;OrderID=39605635" data-viewcommandactive="1" data-originalelementname="input" xpath="1">  <i class="fa fa-arrow-up"></i> <span>הקפצת מודעה</span></span>

button2

<span data-fieldid="9537" id="bounceRatingOrderBtn" name="bounceRatingOrderBtn" class="viewCommand viewSize1 viewCommandGreenBtn" data-columnnum="1" data-showonload="1" data-defaultvalue="" data-isrequired="0" data-personalareaviewposition="manage_area" data-ispersonalareaviewable="1" data-ajax_path="//my.yad2.co.il/newOrder/index.php?action=updateBounceListing&amp;CatID=3&amp;SubCatID=0&amp;OrderID=39605688" data-viewcommandactive="1" data-originalelementname="input" xpath="1">  <i class="fa fa-arrow-up"></i> <span>הקפצת מודעה</span></span>

button3

<span data-fieldid="9537" id="bounceRatingOrderBtn" name="bounceRatingOrderBtn" class="viewCommand viewSize1 viewCommandGreenBtn" data-columnnum="1" data-showonload="1" data-defaultvalue="" data-isrequired="0" data-personalareaviewposition="manage_area" data-ispersonalareaviewable="1" data-ajax_path="//my.yad2.co.il/newOrder/index.php?action=updateBounceListing&amp;CatID=3&amp;SubCatID=0&amp;OrderID=39594079" data-viewcommandactive="1" data-originalelementname="input" xpath="1">  <i class="fa fa-arrow-up"></i> <span>הקפצת מודעה</span></span>

My Python code:

for i in driver.find_elements_by_class_name("viewCommand viewSize1 viewCommandGreenBtn"):
    print('here')
    i.click()

1 Answer 1

1

Compound classes are represented like this in CSS

classOne.classTwo.classThree {
    //...
}

Try doing

for btn in driver.find_elements_by_css_selector('viewCommand.viewSize1.viewCommandGreenBtn'):
    btn.click()
Sign up to request clarification or add additional context in comments.

8 Comments

Tried that It does not even enter the loop.., I dont know why, the only way I got it to work is by xpath
@yarinCohen Have you tried just doing print(driver.find_elements...) to check if it returns anything?
I checked the length of it and it's 0, I can post the full HTML code if it will help
What if you prepend a . to the selector? So do driver.find_elements_by_css_selector('.viewCommand.viewSize1.viewCommandGreenBtn'). Does that work?
Same result, Could it be because it is in an iframe?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.