SeleniumBase - 无法使用值、文本、索引从下拉列表中选择值

问题描述 投票:0回答:1

我正在致力于使用 SeleniumBase + Python 实现工作流程自动化。我遇到了这个特定网页的问题,我想单击下拉菜单并从提供给我们的选项列表中选择一个值。

我尝试过使用以下方法:

self.click('//*[@id="-1_PersonProfileFields.AddressCountry"]')
self.send_keys("India")
self.select_option_by_index("//*[@id='-1_PersonProfileFields.AddressCountry']",45)
self.click('select#-1_PersonProfileFields.AddressCountry')
self.send_keys("India")

但是,我在每个方法中都面临 NoSuchElementException 错误。

完整代码如下:

from seleniumbase import BaseCase,Driver
import time
BaseCase.main(__name__, __file__)

class MyTestClass(BaseCase):
    def test_demo_site(self):
      self.get("https://careers-se.icims.com/jobs/67282/area-sales-manager---distributor/candidate?from=login&eem=VALI7WbuYjsYNVeTcJFe1Lp4NyzhJKL%252BgGk896dMArDy6SnRigcgxLtwQv3zbEEv&code=d4da33efe18fb5649da3012875a78ef45945b558aebf7cc0ab3716dce83614e7&ga=c2c2d57aa55f3a4b29a0cfc15e12e9e57cc3deaa024a3a5bc8be5724f93cc0b2&accept_gdpr=1&gdpr_consent_type=37002057002")
      time.sleep(5)
      self.switch_to_frame_of_element("//*[@id='PersonProfileFields.FirstName']")
      self.type("//*[@id='PersonProfileFields.FirstName']","Saul")
      time.sleep(10)
      self.select_option_by_index("//[@id='-1_PersonProfileFields.AddressCountry']",45)
      input("Continue")

请让我知道我在哪里犯了错误以及如何纠正。

谢谢你!

python-3.x selenium-webdriver xpath seleniumbase
1个回答
0
投票

抱歉,我无法提供帮助

SeleniumBase
。但是,如果您有兴趣,请参考仅使用 selenium-python 的工作解决方案(带有内联解释)。

import time
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.maximize_window()
driver.get('https://careers-se.icims.com/jobs/67282/area-sales-manager---distributor/candidate?from=login&eem=VALI7WbuYjsYNVeTcJFe1Lp4NyzhJKL%252BgGk896dMArDy6SnRigcgxLtwQv3zbEEv&code=d4da33efe18fb5649da3012875a78ef45945b558aebf7cc0ab3716dce83614e7&ga=c2c2d57aa55f3a4b29a0cfc15e12e9e57cc3deaa024a3a5bc8be5724f93cc0b2&accept_gdpr=1&gdpr_consent_type=37002057002')
wait = WebDriverWait(driver, 10)

# Switch into the frame
wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID, "icims_content_iframe")))

# Click on the dropdown
wait.until(EC.element_to_be_clickable((By.ID, "-1_PersonProfileFields.AddressCountry_icimsDropdown"))).click()

# Send text "India" to text search field
wait.until(EC.element_to_be_clickable((By.XPATH, "(//*[@class='dropdown-search'])[1]"))).send_keys("India")

# Click on the dropdown item 'India'
wait.until(EC.element_to_be_clickable((By.XPATH, "//li[@title='India']"))).click()
time.sleep(10)
© www.soinside.com 2019 - 2024. All rights reserved.