Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Python 3和Selenium在表单框中输入特定文本_Python_Selenium_Web Scraping - Fatal编程技术网

使用Python 3和Selenium在表单框中输入特定文本

使用Python 3和Selenium在表单框中输入特定文本,python,selenium,web-scraping,Python,Selenium,Web Scraping,我正在写一个代码,可以自动为在线商店创建订单。我在firefox驱动程序中使用Python3和Selenium def change_address(browser,data): ui.WebDriverWait(browser, 60).until(EC.visibility_of_element_located((By.LINK_TEXT, "Edit"))) browser.find_element_by_link_text("Edit").click() while True:

我正在写一个代码,可以自动为在线商店创建订单。我在firefox驱动程序中使用Python3和Selenium

def change_address(browser,data):
ui.WebDriverWait(browser, 60).until(EC.visibility_of_element_located((By.LINK_TEXT, "Edit")))
browser.find_element_by_link_text("Edit").click()
while True:
    try:
        ui.WebDriverWait(browser, 5).until(EC.visibility_of_element_located((By.NAME, "contactPerson")))
        break
    except:
        browser.find_element_by_link_text("Edit").click()
fill_field_by_name(browser,"contactPerson",unidecode.unidecode(data["Full Name (Billing)"]))
choose_option_from(browser,"#address-main > div.sa-form > div:nth-child(4) > div > select",data["Country Name (Billing)"])
try:
    data["Address 1 (Billing)"] = str(int(float(data["Address 1  (Billing)"])))
except:
    pass
fill_field_by_name(browser,"address",unidecode.unidecode(data["Address 1 (Billing)"]))
try:
    data["Address 2 (Billing)"] = str(int(float(data["Address 2 (Billing)"])))
except:
    pass
fill_field_by_name(browser,"address2",unidecode.unidecode(data["Address 2 (Billing)"]))
fill_field_by_name(browser,"city",unidecode.unidecode(data["City (Billing)"]))
if not choose_option_from(browser,"#address-main > div.sa-form > div.row.sa-form-group.sa-province-group > div > select",data["State Name (Billing)"]):
    try:
        fill_field_by_name(browser,"province",unidecode.unidecode(data["State Name (Billing)"]))
    except:
        pass
这个函数告诉脚本输入特定信息。我的主要问题在最后一行

    try:
        fill_field_by_name(browser,"province",unidecode.unidecode(data["State Name (Billing)"]))
    except:
        pass
我需要的不是传递,而是输入一个特定的文本,在这种情况下-,请选择-,这样当它不识别状态时,它只选择-,请选择-,而不是选择任何选项,但我不知道怎么做

希望有人能给我一个提示或引导我通过。谢谢大家!