2

I am not able to click the button using selenium and move to the next page. I have tried the following commands:

driver.find_element_by_xpath(".//div[text()='Production']").click() 
driver.find_element_by_xpath('//*[@id="root"]/div/[1]/div/div/div[2]/button[2]').click 

I have added a screenshot of the html.

enter image description here

What am I doing wrong?

1
  • The second line you sent is missing the brackets after .click Commented Nov 15, 2021 at 19:37

2 Answers 2

4

I guess the pagination button is on the bottom of the page, out of the visible screen. If so, to click it you first have to scroll the page down, bring that element into the view and only then click it.
Please try this:

pager = wait.until(EC.presence_of_element_located((By.XPATH, "//div[text()='Production']")))
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(0.5)
actions.move_to_element(pager).perform()
time.sleep(0.5)
driver.find_element_by_xpath("//div[text()='Production']").click() 
Sign up to request clarification or add additional context in comments.

Comments

2

To click on the element with text as Production you can use either of the following Locator Strategies:

  • Using css_selector:

    driver.find_element(By.CSS_SELECTOR, "button.nav-option.nav-option--main > div.section-title").click()
    
  • Using xpath:

    driver.find_element(By.XPATH, "//button[@class='nav-option nav-option--main']/div[@class='section-title']//div[text()='Production']").click()
    

Ideally to click on the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.nav-option.nav-option--main > div.section-title"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='nav-option nav-option--main']/div[@class='section-title']//div[text()='Production']"))).click()
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    

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.