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
  • 22,180
  • 5
  • 32
  • 55
chetan honnavile
  • 398
  • 1
  • 6
  • 19
  • 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

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
  • 134,197
  • 12
  • 106
  • 148
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
  • 183,867
  • 41
  • 278
  • 352