Selenium returns wrong element when search by class/xpath/css
<p>I'm trying to make simple python script that finds non-faded elements on site and click them.</p>

<p>My code:</p>

<pre><code>from selenium import webdriver
ffprofile = webdriver.FirefoxProfile(r"C:/Users/Dan/AppData/Roaming/Mozilla/Firefox/Profiles/q3fhuchn.QAtest")
driver = webdriver.Firefox(ffprofile)

driver.get("https://www.steamgifts.com/giveaways/search?page=1&amp;type=wishlist")
element = driver.find_element_by_class_name("giveaway__row-inner-wrap")
element.find_element_by_class_name("giveaway__heading__name").click()
</code></pre>

<p>In this script Selenium returns wrong element with the similar class name - "giveaway__row-inner-wrap is-faded".</p>

<p>I've tried xpath and css selectors, but result was the same.
It looks like Selenium searches not the exact class name, but the one which contains search query.</p>

<p>Also script works fine with the following expression:</p>

<pre><code>driver.find_element_by_xpath("//div[@class='giveaway__row-inââner-wrap']//a[@classââ='giveaway__heading_ââ_name']").click()
</code></pre>

<p>But I need list of all elements to be able to iterate them.</p>

<p>Here is example of both types of HTML elements:</p>

<pre><code>    &lt;div class="giveaway__row-outer-wrap" data-game-id="707524220"&gt;
        &lt;div class="giveaway__row-inner-wrap is-faded"&gt;
            &lt;div class="giveaway__summary"&gt;
                &lt;h2 class="giveaway__heading"&gt;
                    &lt;a class="giveaway__heading__name" href="/giveaway/FFdQd/call-of-duty-black-ops-iii-multiplayer-starter-pack"&gt;Call of Duty: Black Ops III - Multiplaye...&lt;/a&gt;&lt;span class="giveaway__heading__thin"&gt;(15P)&lt;/span&gt;&lt;a class="giveaway__icon" rel="nofollow" target="_blank" href="http://store.steampowered.com/app/437350/"&gt;&lt;i class="fa fa-steam"&gt;&lt;/i&gt;&lt;/a&gt;&lt;i data-popup="popup--hide-games" class="giveaway__icon giveaway__hide trigger-popup fa fa-eye-slash"&gt;&lt;/i&gt;
                &lt;/h2&gt;
                &lt;div class="giveaway__columns"&gt;
                    &lt;div&gt;&lt;i class="fa fa-clock-o"&gt;&lt;/i&gt; &lt;span title="Tomorrow, 4:59am"&gt;7 hours remaining&lt;/span&gt;&lt;/div&gt;&lt;div class="giveaway__column--width-fill text-right"&gt;&lt;span title="September 12, 2016, 4:01am"&gt;5 days ago&lt;/span&gt; by &lt;a class="giveaway__username" href="/user/Clockknight"&gt;Clockknight&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;
                    &lt;div class="giveaway__links"&gt;
                        &lt;a href="/giveaway/FFdQd/call-of-duty-black-ops-iii-multiplayer-starter-pack/entries"&gt;&lt;i class="fa fa-tag"&gt;&lt;/i&gt; &lt;span&gt;2,552 entries&lt;/span&gt;&lt;/a&gt;
                        &lt;a href="/giveaway/FFdQd/call-of-duty-black-ops-iii-multiplayer-starter-pack/comments"&gt;&lt;i class="fa fa-comment"&gt;&lt;/i&gt; &lt;span&gt;25 comments&lt;/span&gt;&lt;/a&gt;
                    &lt;/div&gt;
                &lt;/div&gt;&lt;a href="/user/Clockknight" class="global__image-outer-wrap global__image-outer-wrap--avatar-small"&gt;&lt;div class="global__image-inner-wrap" style="background-image:url(https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/51/5127d377a5bb8ee65356bcd81e44873824a2e7b5_medium.jpg);"&gt;&lt;/div&gt;&lt;/a&gt;&lt;a class="global__image-outer-wrap global__image-outer-wrap--game-medium" href="/giveaway/FFdQd/call-of-duty-black-ops-iii-multiplayer-starter-pack"&gt;&lt;div class="global__image-inner-wrap" style="background-image:url(https://steamcdn-a.akamaihd.net/steam/apps/437350/capsule_184x69.jpg);"&gt;&lt;/div&gt;
            &lt;/a&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="giveaway__row-outer-wrap" data-game-id="8668"&gt;
        &lt;div class="giveaway__row-inner-wrap"&gt;
            &lt;div class="giveaway__summary"&gt;
                &lt;h2 class="giveaway__heading"&gt;
                    &lt;a class="giveaway__heading__name" href="/giveaway/MsP6N/chaos-on-deponia"&gt;Chaos on Deponia&lt;/a&gt;&lt;span class="giveaway__heading__thin"&gt;(100P)&lt;/span&gt;&lt;a class="giveaway__icon" rel="nofollow" target="_blank" href="http://store.steampowered.com/app/220740/"&gt;&lt;i class="fa fa-steam"&gt;&lt;/i&gt;&lt;/a&gt;&lt;i data-popup="popup--hide-games" class="giveaway__icon giveaway__hide trigger-popup fa fa-eye-slash"&gt;&lt;/i&gt;
                &lt;/h2&gt;
                &lt;div class="giveaway__columns"&gt;
                    &lt;div&gt;&lt;i class="fa fa-clock-o"&gt;&lt;/i&gt; &lt;span title="Tomorrow, 7:00am"&gt;9 hours remaining&lt;/span&gt;&lt;/div&gt;&lt;div class="giveaway__column--width-fill text-right"&gt;&lt;span title="Today, 5:03pm"&gt;4 hours ago&lt;/span&gt; by &lt;a class="giveaway__username" href="/user/JsxfT"&gt;JsxfT&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;
                    &lt;div class="giveaway__links"&gt;
                        &lt;a href="/giveaway/MsP6N/chaos-on-deponia/entries"&gt;&lt;i class="fa fa-tag"&gt;&lt;/i&gt; &lt;span&gt;84 entries&lt;/span&gt;&lt;/a&gt;
                        &lt;a href="/giveaway/MsP6N/chaos-on-deponia/comments"&gt;&lt;i class="fa fa-comment"&gt;&lt;/i&gt; &lt;span&gt;0 comments&lt;/span&gt;&lt;/a&gt;
                    &lt;/div&gt;
                &lt;/div&gt;&lt;a href="/user/JsxfT" class="global__image-outer-wrap global__image-outer-wrap--avatar-small"&gt;&lt;div class="global__image-inner-wrap" style="background-image:url(https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/90/90b441d2627716a1a4c6be1f8fb375bea590c763_medium.jpg);"&gt;&lt;/div&gt;&lt;/a&gt;&lt;a class="global__image-outer-wrap global__image-outer-wrap--game-medium" href="/giveaway/MsP6N/chaos-on-deponia"&gt;&lt;div class="global__image-inner-wrap" style="background-image:url(https://steamcdn-a.akamaihd.net/steam/apps/220740/capsule_184x69.jpg);"&gt;&lt;/div&gt;
            &lt;/a&gt;
        &lt;/div&gt;
    &lt;/div&gt;
</code></pre>

<p>I would be appreciate if someone can help me with this!</p>

<p>You can try to click on required element using <code>XPath</code>:</p>

<pre><code>driver.find_element_by_xpath('//a[@class="giveaway__heading__name"]').click()
</code></pre>

python html selenium