0

I am trying to click the pagination links (next button). However the click goes to the site homepage. I am targeting the element by class. What could be wrong ?

driver.get('https://www.marinetraffic.com/en/data/?asset_type=vessels&columns=flag,shipname,photo,recognized_next_port,reported_eta,reported_destination,current_port,imo,ship_type,show_on_live_map,time_of_latest_position,lat_of_latest_position,lon_of_latest_position&current_port_in|begins|FUJAIRAH%20ANCH|current_port_in=20585')

# Wait 30 seconds for page to load
timeout = 30
try:
    WebDriverWait(driver, timeout).until(EC.presence_of_element_located((By.CLASS_NAME, 'MuiButtonBase-root-60')))
    element = driver.find_element_by_class_name('MuiButtonBase-root-60')
    driver.execute_script("arguments[0].click();", element)


except TimeoutException:
    print("Timed out waiting for page to load")


driver.quit()
1
  • Please add the html of the element you are trying to click on. Commented Mar 11, 2019 at 5:50

2 Answers 2

1

Use Following Code :

driver.get('https://www.marinetraffic.com/en/data/?

asset_type=vessels&columns=flag,shipname,photo,recognized_next_port,reported_eta,reported_destination,current_port,imo,ship_type,show_on_live_map,time_of_latest_position,lat_of_latest_position,lon_of_latest_position&current_port_in|begins|FUJAIRAH%20ANCH|current_port_in=20585')

# Wait 30 seconds for page to load
timeout = 30
try:
    element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//p[text()='Page']//..//following-sibling::button")))  
    driver.execute_script("arguments[0].click();", element)

except TimeoutException:
    print("Timed out waiting for page to load")


driver.quit()
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you. It worked.. Do you used any tool to copy the XPATH of an element ? When I use chrome Dev Tool. I get something like this. //*[@id="reporting_ag_grid"]/div/div[2]/div[3]/div/div/div/div/div[3]/button[2]
@NoushadMoidunny : give me your gmail id
@NoushadMoidunny : Will help you on hangout call
1

There are 33 elements with this class, find_element_by_class_name returns the first one, (which is located in the header). You can use the footer as starting point to narrow down the options and select the second button using index (there is no difference between the next and previous when both of the are available)

element = WebDriverWait(driver, timeout).until(EC.visibility_of_element_located((By.CSS_SELECTOR, '.r-mtGridFooter-302 button:nth-of-type(2)')))
element.click()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.