0

I have a very simple webpage expecting to click on "NEXT" button after inputting an activation code. But i am not able to find the element by value/name "next" .From the inspect element

<input type="submit" name="activationpage1:j_id_id18" value="Next &gt;&gt;" style="font-family:Arial,sans-serif;font-size:11px;text-align:center;" />

How can I achieve this in python code to click on the button named Next>>?

JeffC
  • 19,228
  • 5
  • 29
  • 49
chetan honnavile
  • 352
  • 4
  • 17
  • 1
    Search for an element with `name="activationpage1:j_id_id18"` or `value="Next >>"`. – John Gordon Jan 08 '20 at 23:12
  • Please add the code you have tried to click next with. – Jortega Jan 08 '20 at 23:14
  • @Jortegafrom selenium import webdriver driver = webdriver.Safari() driver.get("http://acttivatexample.com/first/fast/actvn/") activkey = driver.find_element_by_id("showActivation") activkey.send_keys("mykey") driver.find_element_by_name("next").click() – chetan honnavile Jan 08 '20 at 23:17
  • why do you use name `"next"` if in code you have `name="activationpage1:j_id_id18"` - you have to use `find_element_by_name("activationpage1:j_id_id18")` – furas Jan 08 '20 at 23:45
  • See: [How do I do X?](https://meta.stackoverflow.com/questions/253069/whats-the-appropriate-new-current-close-reason-for-how-do-i-do-x) The expectation on SO is that the user asking a question not only does research to answer their own question but also shares that research, code attempts, and results. This demonstrates that you’ve taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer! See also: [ask] – JeffC Jan 10 '20 at 05:05

2 Answers2

2

This element has name "activationpage1:j_id_id18" so use

driver.find_element_by_name("activationpage1:j_id_id18")

Or you can use xpath like

driver.find_element_by_xpath('//input[@name="activationpage1:j_id_id18"]')

driver.find_element_by_xpath('//input[@value="Next &gt;&gt;"]')

driver.find_element_by_xpath('//input[@type="submit"]')

driver.find_element_by_xpath('//input[@style="font-family:Arial,sans-serif;font-size:11px;text-align:center;"]')
furas
  • 119,752
  • 10
  • 94
  • 135
0

To click() on the element with text as Next >> you have 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, "input[name^='activationpage'][value^='Next'][type='submit']"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[starts-with(@name,'activationpage') and starts-with(@value,'Next')][@type='submit']"))).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
    
undetected Selenium
  • 151,581
  • 34
  • 225
  • 281