0

I'm browsing a list which is made of several nested elements. On one of them an onwheel event is defined.

At the begining of my script I'm using the following lines in a loop:

element_to_hover_over = driver.find_element_by_xpath(MY_XPATH)
hover = ActionChains(driver).move_to_element(element_to_hover_over).perform()

This works very well. Elements are highlighted and I can use a .click() function on them. When I reach the end of the visible part of the list, I start to use the following function found here

def wheel_element(element, deltaY = 120, offsetX = 0, offsetY = 0):
  error = element._parent.execute_script("""
  var element = arguments[0];
  var deltaY = arguments[1];
  var box = element.getBoundingClientRect();
  var clientX = box.left + (arguments[2] || box.width / 2);
  var clientY = box.top + (arguments[3] || box.height / 2);
  var target = element.ownerDocument.elementFromPoint(clientX, clientY);

 for (var e = target; e; e = e.parentElement) {
  if (e === element) {
    target.dispatchEvent(new MouseEvent('mouseover', {view: window, bubbles: true, cancelable: true, clientX: clientX, clientY: clientY}));
    target.dispatchEvent(new MouseEvent('mousemove', {view: window, bubbles: true, cancelable: true, clientX: clientX, clientY: clientY}));
    target.dispatchEvent(new WheelEvent('wheel',     {view: window, bubbles: true, cancelable: true, clientX: clientX, clientY: clientY, deltaY: deltaY}));
    return;
   }
 }    
 return "Element is not interactable";
 """, element, deltaY, offsetX, offsetY)
if error:
 raise WebDriverException(error)

The list scroll perfectly. The problem is that after using the scroll function the hover action doesn't work anymore. There is no error message, but the element is not highlighted as it is before. The XPATH is correct as I'm able to read the content of the element until the end of the list (after the scroll).

When I try to perform a .click() on one of thoose element it generates the following error although it works on the first lines of the list.

AttributeError: 'NoneType' object has no attribute 'click'

Does anyone have an idea to solve this ?

Eric
  • 95
  • 7
  • Could you try `hover = ActionChains(driver).move_to_element(element_to_hover_over).build().perform()`. the exception `AttributeError: 'NoneType' object has no attribute 'click'` suggests that the WebElement is not found and hence resulting in calling click method on `None`, which results in this issue – Naveen Kumar R B Apr 02 '18 at 17:52
  • AttributeError: 'ActionChains' object has no attribute 'build' – Eric Apr 03 '18 at 07:55
  • 1
    I found the solution. The script is going too fast. As the list is built dynamicaly all the parameters are not available at once, I needed to slow down the script and it work – Eric Apr 03 '18 at 07:59

0 Answers0