我想选择的下拉菜单是存放在div中的,所以我不能使用Select()类。
<div waccolumn="" id="segmentoSelect" class="is-3 column"><label class="label">Canal/Segmento</label><div class="control"><ft-segmentos><div class="control"><wac-select><ng-select class="select-custom ng-select ng-select-single ng-select-searchable ng-select-clearable ng-valid ng-touched ng-dirty ng-select-bottom"><div class="ng-select-container"><div class="ng-value-container"><div class="ng-placeholder"></div><!----><!----><div role="combobox" aria-haspopup="listbox" class="ng-input" aria-expanded="false"><input aria-autocomplete="list" type="text" autocorrect="off" autocapitalize="off" autocomplete="ae8bad186fc7" class="user-success"></div></div><!----><!----><span class="ng-arrow-wrapper"><span class="ng-arrow"></span></span></div><!----></ng-select></wac-select></div></ft-segmentos></div></div>
我试着用一个不同的xpath,在标签名上有 "input"。
<input aria-autocomplete="list" type="text" autocorrect="off" autocapitalize="off" autocomplete="ae8bad186fc7" class="user-success" aria-activedescendant="ae8bad186fc7-0" aria-controls="ae8bad186fc7">
并试图发送我想作为该路径的关键的选项名称。
rota = automate.bot.find_element_by_xpath("/html/body/app-root/ft-home/div/main/div/wac-escolha-seguimento/ft-escolha-segmento/div/div[1]/div/ft-segmentos/div/wac-select/ng-select/div/div/div[2]/input")
rota.clear
rota.send_keys("ROTA")
It seems to work for the first menu but for the second:
vigencia = automate.bot.find_element_by_xpath("/html/body/app-root/ft-home/div/main/div/wac-escolha-seguimento/ft-escolha-segmento/div/div[2]/div/wac-select/ng-select/div/div/div[2]/input")
vigencia.clear
vigencia.send_keys("ROTA_1_12_2021")
I'm getting this error:
ElementNotInteractableException: Message: element not interactable
(Session info: headless chrome=95.0.4638.69)
我如何选择选项,如何知道click()方法是否起作用?
EDIT:
找到了解决div问题的方法。
Selecting a combobox option with a <div> tag using Selenium and Python
现在我选择了下拉选项的元素,并点击了选项,但仍然无法在Selenium中打开点击选项的动作所产生的页面。
在我的机器人类里面做了一个函数来选择。
def click_elem(self,path):
bot = self.bot
element = bot.find_element_by_xpath(path)
bot.implicitly_wait(10) # seconds
element.click()
drop_down_rota = "/html/body/app-root/ft-home/div/main/div/wac-escolha-seguimento/ft-escolha-segmento/div/div[1]/div/ft-segmentos/div/wac-select/ng-select/div"
drop_down_vigencia = "/html/body/app-root/ft-home/div/main/div/wac-escolha-seguimento/ft-escolha-segmento/div/div[2]/div/wac-select/ng-select/div"
drop_down_unidade = "/html/body/app-root/ft-home/div/main/div/wac-escolha-seguimento/ft-escolha-segmento/div/div[3]/div/wac-select/ng-select/div"
rota = '/html/body/app-root/ft-home/div/main/div/wac-escolha-seguimento/ft-escolha-segmento/div[1]/div[1]/div/ft-segmentos/div/wac-select/ng-select/ng-dropdown-panel/div/div[2]/div[2]'
vigencia = '/html/body/app-root/ft-home/div/main/div/wac-escolha-seguimento/ft-escolha-segmento/div/div[2]/div/wac-select/ng-select'
unidade = "/html/body/app-root/ft-home/div/main/div/wac-escolha-seguimento/ft-escolha-segmento/div/div[3]/div/wac-select/ng-select"
filtrar = "/html/body/app-root/ft-home/div/main/div/wac-escolha-seguimento/ft-escolha-segmento/div/div[4]/wac-button/button"
automate.bot.implicitly_wait(10) # seconds
automate.bot.get("https://freightech.ambev.com.br/#/escolha-segmento")
automate.click_elem(drop_down_rota)
automate.click_elem(rota)
automate.click_elem(drop_down_vigencia)
automate.click_elem(vigencia)
automate.click_elem(drop_down_unidade)
automate.click_elem(unidade)
automate.click_elem(filtrar)
在我点击()过滤器后,Selenium应该显示这些选项。
但当我试图找到这些元素时,它返回一个空列表或 "find_element_by_xpath "的错误。
automate.bot.find_element_by_xpath('/html/body/app-root/ft-home/div/main/div/wac-escolha-seguimento/ft-escolha-segmento/div[2]/div/div[1]/wac-card-fav/div')