我已经尝试了所有可能的方法。另外,尝试搜索尝试过的不同组合和变体。我可以单击元素以打开下拉菜单。但我无法在其中选择一个选项。我尝试了动作,sendkeys,keys.down / enter以及其他多种功能。但是,它没有帮助。那是我唯一坚持的事情。
//选择办公室
1.driver.findElement(By.id(“ DG5QEPn”))。click();
Action动作=新的Actions(驱动程序); actions.moveToElement(driver.findElement(By.xpath(“ // * [@ id =” DG5QEPn“] / div / div / div1 / div1”)))。click();
driver.findElement(By.id(“ DG5QEPn”))。click();
driver.findElement(By.id(“ DG5QEPn”))。sendKeys(“ RTP HQ”); driver.findElement(By.id(“ DG5QEPn”))。sendKeys(Keys.Down); driver.findElement(By.id(“ DG5QEPn”))。sendKeys(Keys.Enter);
HTML- 在下图中。
答案 0 :(得分:2)
您应该列举所有选项,然后单击所需的选项。看看this。
编辑
我发现最简单的方法是按照以下方式进行操作:
el = driver.find_element_by_id('id_of_select')
for option in el.find_elements_by_tag_name('option'):
if option.text == 'The Options I Am Looking For':
option.click() # select() in earlier versions of webdriver
break
答案 1 :(得分:0)
以下代码对我有用
WebElement selectMyElement = driver.findElement(this.getObject(By.Id(“ Drop of Your Down”)))); selectMyElement.click();
Actions KeyDown = new Actions(driver); keyDown.sendKeys(Keys.chord(Keys.DOWN,Keys.DOWN,Keys.ENTER))。perform();