jung
jung

Reputation: 1

How can open href at python?

I want to open 'text' botton but I can't open it. How can I do?

from selenium import webdriver
import time

driver = webdriver.Chrome(path)
driver.get("https://www.pdfescape.com/account/unregistered/")
time.sleep(0.5)
elem = driver.find_element_by_id("dStartNew").click()
time.sleep(0.5)
elem = driver.find_element_by_id("PdfNew_input_pc").click()
driver.find_element_by_css_selector("[value=\"2\"]").click()
#time.sleep(0.5)
elem = driver.find_element_by_id("PdfNew_input_ps").click()
driver.find_element_by_css_selector("[value=\"a4\"]").click()
#time.sleep(0.5)
driver.find_element_by_xpath('//*[@id="PdfNew_form"]/input[1]').click()
time.sleep(0.5)
driver.find_elements_by_class_name('Add-Text').click()

Problem code : driver.find_elements_by_class_name('Add-Text').click()

Upvotes: 0

Views: 58

Answers (2)

PowerStat
PowerStat

Reputation: 3819

The element you wanted to click has no class name - it has the title "Add Text", also you are using find_elements instead of find_element which changes the result type.

So you could select it with:

driver.find_element_by_css_selector('a[title=\"Add Text\"]').click()

Also please let me add another improvement:

driver.find_element_by_xpath('//*[@id="PdfNew_form"]/input[1]').click()

could be much more stable (for the case of page changes) written as:

driver.find_element_by_css_selector('input[type=\"submit\"]').click()

Upvotes: 1

Sarthak Gupta
Sarthak Gupta

Reputation: 392

driver.find_elements_by_class_name('Add-Text'),click()
  1. Above code should return a list of elements and you can not click on list of elements
  2. This element is not present in the DOM
  3. To click we use '.' instead of ','

Upvotes: 0

Related Questions