0

From couple of days I am trying to find out what is the proper XPATH for the button on the website.

enter image description here

This is the html code of the button:

<div class="rc_library_element_name rc_actionable ia-inline-block" href="reporteditor.phtml?.op=3277&amp;.cr=._%21Mqxtjfi_SFjudmo_SWfssuv&amp;.sess=8Otpr5-9Bz_wpGJTXqAEAPTCP7GkYg..&amp;.done=WvKqgMCoA3IAAEf5xL0AAAAK8">Invoice Detail Report</div>

I have tried a few methods, such as:

invoice_detail_report = wait.until(EC.element_to_be_clickable((By.XPATH, '/html/body/div[2]/div[2]/div[2]/div[2]/div/div[2]/div[5]/div[2]/div[17]/table/tbody/tr/td[2]/div[1]')))

or

invoice_detail_report = wait.until(EC.element_to_be_clickable((By.XPATH, '//DIV[@class="rc_library_element_name rc_actionable ia-inline-block"][text()="Invoice Detail Report"]')))

Unfortunately none of these worked out.

Could you please advise what is the proper xpath for that button?

Thank you very much for your help,

Greetings.

Ivan Beldad
  • 2,285
  • 2
  • 21
  • 33
Bubool
  • 1
  • 1

2 Answers2

0

You can use this Xpath :

//div[contains(text(),'Invoice Detail Report')]

or

//div[contains(@href,'reporteditor.phtml')]

or

this cssSelector :

div[href^='reporteditor.phtml']
cruisepandey
  • 28,520
  • 6
  • 20
  • 38
0

To locate the element with text as Invoice Detail Report and invoke click() on it you can use either of the following strategies :

  • Using XPATH with text :

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[contains(.,'Invoice Detail Report')]"))).click()
    
  • Using XPATH with attributes :

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='c_library_element_name rc_actionable ia-inline-block' and contains(@href,'reporteditor.phtml')]"))).click()
    
  • XPATH using all the attributes :

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='c_library_element_name rc_actionable ia-inline-block' and contains(@href,'reporteditor.phtml') and contains(.,'Invoice Detail Report')]"))).click()
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Hi, thank you for your help, however none of these worked out. Each time I receive a TimeoutException error. I have no idea what's going on there. – Bubool May 09 '18 at 09:02
  • `TimeoutException` is the outcome of _expected-conditions_. Debug your code through `time.sleep()` and `findElement()` if you are able to locate the element and update the question with the observations. – undetected Selenium May 09 '18 at 09:05
  • @Bubool Check out my answer update an let me know the status (new xpath added as a forth option) – undetected Selenium May 09 '18 at 09:12
  • After following steps provided by you, now I receive an error "NoSuchElementException", according to which the program was not able to locate the element. That is strange. – Bubool May 09 '18 at 09:13
  • Good progress. Now you you can solve _NoSuchElementException_ easily through the discussion [Selenium “selenium.common.exceptions.NoSuchElementException” when using Chrome](https://stackoverflow.com/questions/47993443/selenium-selenium-common-exceptions-nosuchelementexception-when-using-chrome/47995294#47995294) – undetected Selenium May 09 '18 at 09:15
  • Alright, I will check out that discussion. By the way the forth option did not help either, however thank you for trying Debanjan – Bubool May 09 '18 at 09:17
  • 1
    Try to separate steps. First, locate the element. Then click on this element. – Zhivko.Kostadinov May 09 '18 at 09:52
  • @Bubool As `findElement()` padded with `time.sleep()` returned _NoSuchElementException_, _WebDriverWait_ will always return _TimeoutException_. So first and foremost you have to address **NoSuchElementException** which wasn't evident from your question description. – undetected Selenium May 09 '18 at 09:52
  • 1
    `WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.LINK_TEXT, "Invoice Detail Report"))).click()` This answer is wrong, Link_text can't be used unless it is `` – Rajagopalan May 09 '18 at 11:01
  • I am struggling with addressing the NoSuchElementException, because when I have used the "try and except", it said that "NameError: name 'NoSuchElementException' is not defined. – Bubool May 09 '18 at 11:03