Python+Selenium, can't click the 'button' wrapped by span
<p>I am new to selenium here. I am trying to use selenium to click a 'more' button to expand the review section everytime after refreshing the page. </p>

<p>The website is TripAdvisor. The logic of <code>more</code> button is, as long as you click on the first <code>more</code> button, it will automatically expand all the review sections for you. In other words, you just need to click on the first 'more' button. </p>

<p>All buttons have a similar class name. An example is like <code>taLnk.hvrIE6.tr415411081.moreLink.ulBlueLinks</code>. Only the numbers part changes everytime. </p>

<p>The full element look like this:</p>

<pre><code>&lt;span class="taLnk hvrIE6 tr413756996 moreLink ulBlueLinks" onclick="          var options = {
      flow: 'CORE_COMBINED',
      pid: 39415,
      onSuccess: function() { ta.util.cookie.setPIDCookie(2247); ta.call('ta.servlet.Reviews.expandReviews', {type: 'dummy'}, ta.id('review_413756996'), 'review_413756996', '1', 2247);; window.location.hash = 'review_413756996'; }
    };
    ta.call('ta.registration.RegOverlay.show', {type: 'dummy'}, ta.id('review_413756996'), options);
    return false;
  "&gt;
More&amp;nbsp; &lt;/span&gt;
</code></pre>

<p>I have tried several ways to get the button click. But since it is an onclick event wrapped by span, I can't successfully get it clicked. </p>

<p>My last version looks like this:</p>

<pre><code>driver = webdriver.Firefox()
driver.get(newurl)
page_source = driver.page_source
soup = BeautifulSoup(page_source)
moreID = soup.find("span", class_=re.compile(r'.*\bmoreLink\b.*'))['class']
moreID = '.'.join(moreID[0:(len(moreID)+1)])
moreButton = 'span.' + moreID
button = driver.find_element_by_css_selector(moreButton)
button.click()
time.sleep(10)
</code></pre>

<p>However, I keep getting the error message like this: </p>

<blockquote>
  <p>WebDriverException: Message: Element is not clickable at point (318.5,
  7.100006103515625). Other element would receive the click....</p>
</blockquote>

<p>Can you advise me on how to fix the problem? Any help will be appreciated!</p>

<blockquote>
  <p>WebDriverException: Message: Element is not clickable at point (318.5, 7.100006103515625). Other element would receive the click....</p>
</blockquote>

<p>This error to be occur when element is not in the view port and selenium couldn't click due to some other overlay element on it. In this case you should try one of these following solution :- </p>

<ul>
<li><p>You can try using <code>ActionChains</code> to reach that element before click as below :-</p>

<pre><code>from selenium.webdriver.common.action_chains import ActionChains

button = driver.find_element_by_css_selector(moreButton)

ActionChains(button).move_to_element(element).click().perform()
</code></pre></li>
<li><p>You can try using <code>execute_script()</code> to reach that element before click as :-</p>

<pre><code>driver.execute_script("arguments[0].scrollIntoView(true)", button)
button.click()
</code></pre></li>
<li><p>You can try  using <code>JavaScript::click()</code> with <code>execute_script()</code> but this <code>JavaScript::click()</code> defeats the purpose of the test. First because it doesn't generate all the events like a real click (focus, blur, mousedown, mouseup...) and second because it doesn't guarantee that a real user can interact with the element. But to get rid from this issues you can consider it as an alternate solution.</p>

<pre><code>driver.execute_script("arguments[0].click()", button)
</code></pre></li>
</ul>

<p><strong>Note</strong>:- Before using these options make sure you're trying to interact with correct element using with correct locator, otherwise <code>WebElement.click()</code> would work well after wait until element visible and clickable using <code>WebDriverWait</code>.</p>

python selenium onclick css-selectors webdriver