Rookie programmer
Rookie programmer

Reputation: 25

Cannot locate and click an element using Selenium and Python

I really tried almost everything that comes on my mind to click on buttons No

Bellow is an entire HTML code of it

<div class="row nest">
   <div class="condition-row clearfix" id="condition_row_1">
      <div class="field small-12 medium-6 columns">
         <label>
         Does this item still have the retail tags attached? <span>*</span>
         </label>
         <div class="btn-group elastic">
            <a class="pill condition-tags btn white sml ">Yes</a><a class="pill condition-tags btn white sml ">No</a>        
         </div>
         <p class="error clearfix" id="condition-tags_error" style="display: none;">Please select an answer</p>
         <input class="required" type="hidden" id="property[condition-tags]" name="property[condition-tags]" value="">
      </div>
      <div class="field small-12 medium-6 empty columns"></div>
   </div>
   <div class="condition-row clearfix" id="condition_row_2">
      <div class="field small-12 medium-6 columns">
         <label>
         Does this item have any signs of wear? <span>*</span>
         </label>
         <div class="btn-group elastic">
            <a class="pill condition-wear btn white sml ">Yes</a><a class="pill condition-wear btn white sml ">No</a>        
         </div>
         <p class="error clearfix" id="condition-wear_error" style="display: none;">Please select an answer</p>
         <input class="required" type="hidden" id="property[condition-wear]" name="property[condition-wear]" value="">
      </div>
      <div class="field small-12 medium-6 empty columns"></div>
   </div>
   <div class="condition-row clearfix" id="condition_row_3">
      <div class="clearfix"></div>
      <div class="field small-12 columns" id="condition-custom-outer" style="display: none;">
         <hr class="hr-line">
         <label>Tag any signs of wear.</label>
         <div class="btn-group elastic">
            <a class="pill condition-list btn white sml ">Scuffs or scratches</a><a class="pill condition-list btn white sml ">Damaged or missing stones</a><a class="pill condition-list btn white sml ">Tarnishing</a>            <a class="condition-add-custom btn white sml" id="condition-add-custom" href="javascript:void(0);">
            <span class="icon-plus-solid"></span>Add your own
            </a>
         </div>
         <div class="clearfix"></div>
         <hr class="hr-line">
         <label>Note</label>
         <textarea class="condition-notes" placeholder="Please describe wear or damage in detail." id="property[condition-note]" name="property[condition-note]"></textarea>
         <input class="customConditions" type="hidden" id="property[condition-list]" name="property[condition-list]" value="">
      </div>
      <div class="field small-12 medium-6 empty columns"></div>
   </div>
</div>

Tried with XPATH,CSS_SELECTOR, LINK_TEXT

All available methods

Seems none of them working.

try:
    WebDriverWait(driver, 10).until(
        EC.element_to_be_clickable((By.XPATH,'/html/body/div[3]/div/div/div[2]/form/div[3]/div[2]/div[1]/div/div[2]/div[1]/div[2]/div/div[1]/div[1]/div/a[2]'))).click()
except:
    errorDuringFill = True

Button on screenshot

Using FIREFOX

Live purpose available on : https://www.tradesy.com/sell/

Category : Shoes ... & Accessories & Jewelry & Bracelets

Upvotes: 0

Views: 159

Answers (3)

Stuart
Stuart

Reputation: 474

This answer taken from: Can not click on a Element: ElementClickInterceptedException in Splinter / Selenium

You can try the below 2 methods to click on element.

element = driver.find_element_by_css('div[class*="loadingWhiteBox"]')
driver.execute_script("arguments[0].click();", element)

element = driver.find_element_by_css('div[class*="loadingWhiteBox"]')
webdriver.ActionChains(driver).move_to_element(element ).click(element ).perform()

hope this will work.

Upvotes: 1

Svetlana Levinsohn
Svetlana Levinsohn

Reputation: 1556

I'd try to link to the condition-row class above, just to exclude similar components of that page. And then we can use the class of a and text()

Try this:

driver.implicitly_wait(4)
e = driver.find_element_by_xpath("//div[contains(@class,'condition-row')]//a[contains(@class,'condition-tags') and text()='No']")
e.click()

Upvotes: 0

Hrisimir Dakov
Hrisimir Dakov

Reputation: 587

Try changing the xpath to:

"//div[contains(@class,'condition-row')]//a[contains(.,'No')]"

You should really take some time and read on locators, instead of copying the full path from the inspector - it will make your job easier, and your day happier.

Upvotes: 0

Related Questions