Reputation: 21
Scenario: Login to www.makemytrip.com --> click on My Account link --> Click on Profile option --> Personal Information pop up comes up
The title field in the Personal Information pop up is of type 'button' in makemytrip website.
I am not sure how to select value(Mr.,Mrs., Miss. etc) from the title field. The title field has a default value - 'Mr.' but in my script I want to select 'Mrs.'.
The below code does not work.
driver.findElement(By.xpath("//button[contains(@data-id,'PTitle')]")).sendKeys("Mrs.");
I can not use Select as its not of type dropdown. Kindly advice on how I can code to select different values from the Title field of type button.
Upvotes: 0
Views: 650
Reputation: 21
Thank you for your response. I used the below code and it worked as expected.
WebDriverWait wait = new WebDriverWait(driver,30); driver.findElement(By.xpath("//button[contains(@data-id,'PTitle')]")).click(); wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Mrs."))).click();
Upvotes: 1
Reputation: 12528
The reason your code will not work is because it requires 2 events before you can actually change that value. First action is clicking the button element, and then second action is clicking the other option in the dropdown (which in you case is a ul inside a div element).
In ruby (just translate to Java), you would need to do something like this:
sal_elem = webdriver.find_element(xpath: "//button[contains(@data-id, 'PTitle')")
sal_elem.click()
=> Because you clicked on the button, the other elements (Mr, Mrs, Ms..) would become visible to you now and you can find and click (ex. change to Ms)
new_sal_elem = webdriver.find_element(xpath: "//a[contains(@data-normalized-text, 'Ms.')]")
new_sal_elem.click()
Obviously these are raw commands and should always be placed inside begin-rescue blocks (or in Java, try-catch) and should factor in wait until.
Upvotes: 0