0

there is a website with the following HTML-Code-snippet:

<li class="quest" data-questid="Battle_02" data-category="battle">
<img src="img/x.gif" alt="" class="reward">
<a href="#">Versteck bauen</a>
</li>

I want to click on this list item. The only list item with the img inside. I find the items with xpath. And tried to click on them. I tried it with the "li" token:

xpath = "//img[@class='reward']/parent::*"

With the img:

xpath = "//img[@class='reward']

And with the "a href":

xpath = "//img[@class='reward']//following::*"

Then I'm trying to click on it with the following code:

click_me = self.browser.find_element_by_xpath(xpath)
click_me.click()

But I get an Element is not clickable at point exception.

So I tried it with an action:

action = ActionChains(self.browser)
action.move_to_element(click_me).click().perform()

and with:

action.move_to_element(click_me).move_by_offset(4,0).click().perform()

I don't get an error with this but it still doesn't work.

EDIT: Used chrome-driver 2.31. Switching to 2.34 solved my problem!

SamuelTJackson
  • 1,357
  • 3
  • 19
  • 40
  • 1
    Please update question to list which browser and browser version, webdriver version you used? chromdriver 2.33 has an know issue on click any element not in viewport. If you use this version, please use 2.34 or heigher. – yong Feb 02 '18 at 03:27
  • I was using 2.31. switching to 2.34 solved the problem. thank you – SamuelTJackson Feb 02 '18 at 10:19

3 Answers3

1

As you wanted to click on the list item, you have tried the following :

  • xpath = "//img[@class='reward']/parent::*" : which refers the parent of the <img> tag and may not work.

  • xpath = "//img[@class='reward'] : may not work as it doesn't have any onClick() event.

  • xpath = "//img[@class='reward']//following::*" : would locate all the nodes present in document from the <img> node.

Solution

You can use any of the following options :

  • Using link_text :

    self.browser.find_element_by_link_text("Versteck bauen").click()
    
  • Using xpath :

    self.browser.find_element_by_xpath("//li[@class='quest' and @data-category='battle']//a[contains(normalize-space(), 'Versteck bauen')]").click()
    

Note : If you still face Element is not clickable at point... exception refer to this discussion.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

Could you please try with by adding build() function in-between such as:

action.move_to_element(click_me).move_by_offset(4,0).click().build().perform()

The build() function is used for stitching Actions class functions together.

Rishi Khanna
  • 409
  • 1
  • 5
  • 16
0

Please update question to list which browser and browser version, webdriver version you used? chromdriver 2.33 has an know issue on click any element not in viewport. If you use this version, please use 2.34 or heigher. – yong

SamuelTJackson
  • 1,357
  • 3
  • 19
  • 40