Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.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 selenium webdriver选择选项不起作用_Python_Selenium Webdriver_Drop Down Menu - Fatal编程技术网

python selenium webdriver选择选项不起作用

python selenium webdriver选择选项不起作用,python,selenium-webdriver,drop-down-menu,Python,Selenium Webdriver,Drop Down Menu,加拿大城市列表中卡尔加里的选择不起作用,按专业语法单击搜索按钮后,它将始终返回搜索结果中的所有城市。这是我的密码: from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait # Initialize driver = webdriver.Firefox() driver.get('https://sjobs.brassring.com/TGWebHost/searchopenin

加拿大城市列表中卡尔加里的选择不起作用,按专业语法单击搜索按钮后,它将始终返回搜索结果中的所有城市。这是我的密码:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait

# Initialize
driver = webdriver.Firefox()
driver.get('https://sjobs.brassring.com/TGWebHost/searchopenings.aspx?partnerid=25222&siteid=5011')
# Select city name Calgary
calgaryOptionXpath = ".//*[@id='Question4138__FORMTEXT62']/option[37]"
calgaryOptionElement = WebDriverWait(driver, 10).until(lambda driver:driver.find_element_by_xpath(calgaryOptionXpath))
calgaryOptionElement.click()
# click submit button "Search"
driver.find_element_by_id('ctl00_MainContent_submit1').click()
提前谢谢

from selenium import webdriver
from selenium.webdriver.support.ui import Select
import time

# Initialize
driver = webdriver.Chrome()
driver.maximize_window()
driver.implicitly_wait(10)
driver.get('https://sjobs.brassring.com/TGWebHost/searchopenings.aspx?partnerid=25222&siteid=5011')



# Select city name Calgary
text = "Calgary"  # what ever you want to select in dropdown
currentselection = driver.find_element_by_id("Question4138__FORMTEXT62")
select = Select(currentselection)
select.select_by_visible_text(text)

select.deselect_by_visible_text("All")

print("Selected Calgary by visible text")

driver.find_element_by_id('ctl00_MainContent_submit1').click()

希望这有帮助

我测试了它,它能工作。谢谢你,先生,我给你买了一瓶啤酒。@Dung-我运行你的代码时总是得到卡尔加里。不确定你的情况有什么问题。答案只是给出了代码,没有说明错误最初发生的原因。他将web元素转换为select,然后与之交互。@testerjoe2请尝试我的代码,我使用了driver:element:click()这不起作用,这就是他说“通过可见文本选择卡尔加里”的原因,他使用select:select:select\u通过可见文本进行选择,这样就行了@粪-它应该只选择卡尔加里,对吗?你的代码实际上为我做到了这一点。我是不是遗漏了什么?@testerjoe2对!这对你来说很好,但不知道为什么对我来说不好。可能是版本控制的问题。