【发布时间】:2022-09-26 16:02:47
【问题描述】:
我正在尝试将字符串与网站上的下拉菜单完全匹配
# Check if a specific position is chosen or if it is left default / empty
if str_sv_pos == \"position\" or str_sv_pos == \"\":
pass
else:
try:
# press on the drop down container
pos_dropdown_menu = init_webdriver.driver.find_element_by_xpath(
\"/html/body/main/section/section/div[2]/div/div[2]/div/div[1]/div[1]/div[4]/div\"
)
pos_dropdown_menu.click()
# define variable \"my_pos_string\" taken out of a input field in my GUI
my_pos_string = str(str_sv_pos)
# choose the correct position from the container list
find_pos = init_webdriver.wait.until(
EC.element_to_be_clickable(
(
By.XPATH,
(
\"//li[@class=\'with-icon\' and contains(text(),\'\"
+ my_pos_string
+ \"\')]\"
),
)
)
)
find_pos.click()
except:
pass
这适用于大多数职位。
但问题是,容器内有一个“LW”和一个“LWB”。并且 \"LWB\" 出现在 \"LW\" 之前,所以它选择了 \"LWB\"。
所以我想完全匹配我在 GUI 中的输入以避免这种情况。
在我的示例中如何做到这一点?
-
在另一篇文章中找到了解决方案:stackoverflow.com/a/60713366/12470444
标签: python string selenium tkinter match