1

I have the below code I've inspected from Chrome. and I am trying to click this object. Ideally leveraging xpath or css selector.

I copied Xpath as below mentioned

/html/body/form/table[4]/tbody/tr/td[1]/table/tbody/tr[3]/td

This is the full path

<td style="text-decoration: none; color: rgb(0, 0, 0); font-family: Arial; font-size: 11px; padding-bottom: 2px; padding-top: 1px; border-bottom: 1px solid rgb(194, 194, 194); background: rgb(255, 255, 255); cursor: auto;" onmouseover="this.style.background='#BED9F5'; this.style.cursor='hand'; showTitle(this,'Review Quotes / Quote To Order',150,true); window.status='Review Quotes / Quote To Order'; return true;" onmouseout="this.style.background='#FFFFFF'; this.style.cursor='auto'; hideTitle(); window.status=' '; return true;" onclick="if (warnUnfinishedPage()) return false; changePage('pc.quote.html.QuoteSummarySection','refresh');  return false;" align="left" width="110" valign="middle" title="Review Quotes / Quote To Order">

&nbsp;&nbsp;Quotes

</td>

Katalon Recorder exported Python as the below few options, but none seem to be working for me. They all come back as no such element. I think it may have something to do with the parentheses?

driver.find_element_by_xpath("//td[@onclick=\"if (warnUnfinishedPage()) return false; changePage('pc.quote.html.QuoteSummarySection','refresh'); return false;\"]").click()

driver.find_element_by_xpath("//tr[3]/td").click()

driver.find_element_by_css_selector("td[title=\"Review Quotes / Quote To Order\"]").click()

Any advice on something else I can try would be much appreciated!

3
  • Do you have any frames on the page? If the url is public, please add in your question. Commented Dec 4, 2018 at 16:30
  • Initially I thought there were no iframes, but now I think there may be. iframe tag=iframe and iframe id=htselFrame Commented Dec 4, 2018 at 17:52
  • Can you share the URL or more of the html? And did you try switching to the iframe (if it is indeed a parent element) with driver.switch_to.frame(driver.find_element_by_css_selector(".htselFrame")) Commented Dec 4, 2018 at 18:19

2 Answers 2

1

The desired element is a JavaScript enabled element so you have to induce WebDriverWait for the element to be clickable and you can use either of the following solutions:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "td[title='Review Quotes / Quote To Order']"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//td[@title='Review Quotes / Quote To Order' and contains(.,'Quotes')]"))).click()
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
Sign up to request clarification or add additional context in comments.

1 Comment

I appreciate the feedback this will be helpful for sure! :) I did however discover another solution which I will post above.
1

The issue was due to a multitude of things. One I needed to implement a command to change active tabs.

The automation I was performing opened up a new tab so I had to leverage the below code to activate that tab.

driver.switch_to.window(driver.window_handles[1])

I also needed to implement a little wait for things to load

driver.implicitly_wait(3)

I also needed to account for iframes. I had multiple iframes so I used the below to print out how many I had

seq = driver.find_elements_by_tag_name('iframe')
    print("Number of frames present in the web page are: ", len(seq))

Then I was able to figure out I had 2 frames and the below code looped through each until the xpath was discovered.

    for x in range(2):
        try:
            driver.switch_to.frame(x)
            driver.find_element_by_xpath("//tr[3]/td").click()
        except:
            print("It's not: ", x)
            continue

Comments

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.