Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Replying to a Javascript/jQuery
#11
(Nov-21-2021, 03:44 PM)gw1500se Wrote: According to the documentation, that should work. I have not been able to find anything useful about this error. The only thing I found was a suggestion to use select_by_visible_text which in my case is going to be a pain as I would have to develop it.
There is own import for this,then most use Select call to get .select_by_visible_text() or .select_by_value() to work.
from selenium.webdriver.support.ui import Select
To give a example whole step-1 finish.
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from bs4 import BeautifulSoup
import time

#--| Setup
options = Options()
#options.add_argument("--headless")
browser = webdriver.Chrome(executable_path=r'C:\cmder\bin\chromedriver.exe', options=options)
#--| Parse or automation
url = "https://www.donotcall.gov/report.html"
browser.get(url)
time.sleep(3)
button_continue = browser.find_elements_by_css_selector('#MainContinueButton')
button_continue[0].click()
# Continue with fill all the form data
time.sleep(3)
phone =  browser.find_elements_by_css_selector('#PhoneTextBox')
phone[0].send_keys("2514455669")
date = browser.find_elements_by_css_selector('#DateOfCallTextBox')
date[0].click()
date_1 = browser.find_elements_by_css_selector('td.ui-datepicker-days-cell-over.ui-datepicker-today > a')
date_1[0].click()

# Time of call
time.sleep(3)
select_time = Select(browser.find_element_by_id('TimeOfCallDropDownList'))
select_time.select_by_visible_text('03:00 AM')
select_min = Select(browser.find_element_by_id('ddlMinutes'))
select_min.select_by_visible_text('02')
time.sleep(3)
# Record, receive and about
time.sleep(3)
record = browser.find_elements_by_css_selector('#PrerecordMessageYESRadioButton')
record[0].click()
receive = browser.find_elements_by_css_selector('#PhoneCallRadioButton')
receive[0].click()
select_about = Select(browser.find_element_by_id('ddlSubjectMatter'))
select_about.select_by_visible_text('Unknown')
# Next step
time.sleep(3)
continue_next = browser.find_elements_by_css_selector('#StepOneContinueButton')
continue_next[0].click()
Reply
#12
I may be confused but I already have that import. 'Select_by_visible_text' does work. It is just 'select_by_value' that causes the traceback. Is it possible that chrome supports it but Firefox does not? I can develop the string for 'visible_text', if I must, but I am really trying to understand why 'by_value' does not work.
Reply
#13
The code you show dos not use Select at all.
hour=browser.find_element_by_css_selector('#TimeOfCallDropDownList')
hour.select_by_value(hh)
See how i do it in my code.
select_time = Select(browser.find_element_by_id('TimeOfCallDropDownList'))
select_time.select_by_visible_text('03:00 AM')
Reply
#14
Ohhhhhhhh! I missed that subtlety. Sorry.
Reply
#15
I'm afraid I still have another problem. When I click the continue button, after all this, I need to see the entire rendered source of the next page. When I look at the HTML source none of the fields established by the javascripts are in the source. I hove no idea what the field names are to select them and fill them in. How do I list all that after the 'click()'?

nextStep=browser.find_element_by_css_selector('#StepOneContinueButton')
time.sleep(5)
nextStep.click()
Reply
#16
(Nov-21-2021, 08:49 PM)gw1500se Wrote: I need to see the entire rendered source of the next page
No need to look at whole source.
I pretty much never look at at entire page source,but use dev-tool right click on element to get only chosen Selector.
So tested the start of step-2 will be like this.
continue_next = browser.find_elements_by_css_selector('#StepOneContinueButton')
continue_next[0].click()
# Step-2
time.sleep(3)
phone1 =  browser.find_elements_by_css_selector('#CallerPhoneNumberTextBox')
phone1[0].send_keys("44556677")
Reply
#17
Thanks. I have not used dev-tools much before.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  POST Reply to Ajax/jQuery (mostly an HTML question) gw1500se 5 2,610 Nov-18-2021, 02:44 PM
Last Post: gw1500se

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020