Python Forum

Full Version: Replying to a Javascript/jQuery
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
(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()
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.
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')
Ohhhhhhhh! I missed that subtlety. Sorry.
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()
(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")
Thanks. I have not used dev-tools much before.
Pages: 1 2