0

My td contains

<tbody id="gridview-1161-body">
 <tr id="gridview-1161-record-19832230" data-boundview="gridview-1161" data-recordid="19832230" data-recordindex="2" class="x-grid-row x-grid-data-row" tabindex="-1">

#supplier item
<td role="gridcell" class="x-grid-cell x-grid-td x-grid-cell-headerId-gridcolumn-1154" id="ext-gen2524">
<div class="x-grid-cell-inner " style="text-align:left;">
<div class="rp-invalid-cell rp-icon-alert-require-field"></div>xxx/div></td>
#id
<td role="gridcell" class="x-grid-cell x-grid-td x-grid-cell-headerId-gridcolumn-1156" id="ext-gen2526">
<div class="x-grid-cell-inner " style="text-align:left;">
<div class="rp-invalid-cell rp-icon-alert-require-field"></div>yy</div></td>
#cost
<td role="gridcell" class="x-grid-cell x-grid-td x-grid-cell-headerId-gridcolumn-1157" id="ext-gen2527">
<div class="x-grid-cell-inner " style="text-align:right;">
<div class="rp-invalid-cell rp-icon-alert-require-field"></div>$15.00</div></td>

#qty - **here i want to set value 10** id is dynamically generating
<td role="gridcell" class="x-grid-cell x-grid-td x-grid-cell-headerId-gridcolumn-1158  rp-grid-editable-cell  rp-grid-editable-cell" id="ext-gen2528">
<div class="x-grid-cell-inner " style="text-align:right;">
<div class="rp-invalid-cell rp-icon-alert-require-field" id="ext-gen2632"></div>&nbsp;</div></td>

</tr><tbody>

i want to click this td and set value as 10 then click enter.I have tried.

e=driver.find_element_by_class_name('x-grid-cell x-grid-td x-grid-cell-headerId-gridcolumn-1158  rp- 
grid-editable-cell  rp-grid-editable-cell').send_keys('10')   
e.send_keys(Keys.ENTER)

and

e=driver.find_element_by_xpath("//div[@class='x-grid-cell x-grid-td x-grid- 
cell-headerId-gridcolumn-1158  rp-grid-editable-cell  rp-grid-editable- 
cell']")
e.send_keys("10")

but im getting

raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".x-grid-cell x-grid-td x-grid-cell-headerId-gridcolumn-1158 rp-grid-editable-cell rp-grid-editable-cell"}

anu priya
  • 23
  • 1
  • 6

2 Answers2

0

Try

e = driver.find_element_by_css_selector('td.x-grid-cell.x-grid-td.x-grid-cell-headerId-gridcolumn-1158.rp-grid-editable-cell.rp-grid-editable-cell')
e.send_keys('10')
e.send_keys(Keys.ENTER)

Plus, i think that this kind of error NoSuchElementException appears when Selenium is unable to find your element. The reasons may be:

  • Your driver.find_element has the wrong parameters, but considering your code, it seems unlikely.
  • The element you try to find is not displayed. You should consider using the wait:

    WebDriverWait(self.driver, time).until(EC.visibility_of_element_located((By.CLASS_NAME, class_name)))
    
ZoulouDu94
  • 115
  • 1
  • 9
0

To click the <td> element, set value as 10 then to click() Enter you have to to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "td.x-grid-cell.x-grid-td.rp-grid-editable-cell[role='gridcell']")))
    element.click()
    element.clear()
    element.send_keys('10')
    element.(Keys.ENTER)
    
  • Using XPATH:

    element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//td[@role='gridcell' and contains(@class, 'rp-grid-editable-cell')]")))
    element.click()
    element.clear()
    element.send_keys('10')
    element.(Keys.ENTER)
    
  • Note : You have to add the following imports :

    from selenium import webdriver
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.common.keys import Keys
    
DebanjanB
  • 118,661
  • 30
  • 168
  • 217
  • i have created more td but "gridcolumn-1158" this thing only unique in class name. – anu priya Dec 13 '19 at 13:37
  • In that case you need to provide more of the outerHTML so the element can be uniquely identified. – DebanjanB Dec 13 '19 at 13:38
  • I still don't find any unique attribute for this `` tag. Maybe some more of the outerHTML would help. – DebanjanB Dec 13 '19 at 13:56
  • once it is click then throwing "raise exception_class(message, screen, stacktrace) selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable" at line element.send_keys('10') – anu priya Dec 13 '19 at 13:56
  • Can you update the question with the HTML of the actual `` tag? – DebanjanB Dec 13 '19 at 14:11