How to perform dropdown in BMC Project using Webdriver

后端 未结 1 1261
深忆病人
深忆病人 2021-01-24 22:54

I am not able to automate dropdown function in my BMC project. Tried lots of options. This will help me a lot. Please help..

相关标签:
1条回答
  • 2021-01-24 23:35

    This is not a select tag and is not designed to be one. It's an additional drop down menu element structured with tr and td tags. So using the Select class will not work.

    Sample high level structure of a select tag:

    <select>
        <option>first option</option>
        <option>second option</option>
    </select
    

    To solve your problem, You could simply use this:

    driver.findElement(By.xpath("//div[@ardbn='Customer']//textarea")).clear();
    driver.findElement(By.xpath("//div[@ardbn='Customer']//textarea")).sendKeys("AARADHANA");
    

    Keep in mind that the text you are entering should be present in the menu. Entering a value that is not present in the list would result in the menu popping up and no value stored in the field, thereby throwing errors when you click on save since this is a mandatory field.

    However if you do want to open the menu and choose something from there, you would have to wait for the element to appear and use one of these:

    If the click needs to be performed on the tr

    driver.findElement(By.xpath("//table[@class='MenuTable']//tr[td[.='AARADHANA']]")).click();
    

    If the click needs to be performed on the td

    driver.findElement(By.xpath("//table[@class='MenuTable']//tr//td[.='AARADHANA']")).click();
    

    Be careful with this though, because 1. There may be many elements with the class 'MenuTable' that are hidden and if they are higher up in the hierarchy the script will fail. 2. If the first issue is not present and the customer you're trying to select is not visible you will have to scroll until the element is found before performing a click.

    Highly recommend using the sendKeys option. Please ensure that you include code snippets to indicate what you've tried. This seems to be an issue with understanding the structure of the element in question.

    0 讨论(0)
提交回复
热议问题