1

I have tried all the possible things. also, tried searching over tried different combinations and variations. I can get the element clicked which opens the dropdown. but i am not able to select an option in it. I tried with actions, sendkeys, keys.down/enter and multiple things as well. however, it didn't help. That's the only thing I am stuck on.

//selecting office

driver.findElement(By.id("DG5QEPn")).click();

// attempt with actions
Actions actions = new Actions(driver);
actions.moveToElement(driver.findElement(By.xpath("//*[@id="DG5QEPn"]/div/div/div1/div1"))).click();

// attempt with sendKeys
driver.findElement(By.id("DG5QEPn")).click();

driver.findElement(By.id("DG5QEPn")).sendKeys("RTP HQ"); 

// attempt with Keys.Down and Keys.Enter
driver.findElement(By.id("DG5QEPn")).sendKeys(Keys.Down); 
driver.findElement(By.id("DG5QEPn")).sendKeys(Keys.Enter);

enter image description here

3
  • It will be good if you give HTML DOM code instead of screenshot Jul 11, 2020 at 1:37
  • <div class="css-fx5u20 react-select__value-container react-select__value-container--has-value"><div class="css-o6m1t9-singleValue react-select__single-value">RTP HQ</div><div class="css-1g6gooi"><div class="react-select__input" style="display: inline-block;"><input autocapitalize="none" autocomplete="off" autocorrect="off" id="select_input_Office" spellcheck="false" tabindex="0" type="text" aria-
    – Safaee
    Jul 13, 2020 at 15:08
  • Please add this in your answer Jul 13, 2020 at 16:11

3 Answers 3

1

Below code worked for me

WebElement selectMyElement = driver.findElement(By.id("DG5QEPn"));

selectMyElement.click();

Thread.sleep(4000);

Actions keyDown = new Actions(driver); keyDown.sendKeys(Keys.chord(Keys.DOWN, Keys.DOWN, Keys.ENTER)).perform();

1
  • Yes, this worked for me. Whereas just doing selectMyElement.sendKeys(Keys.DOWN); over and over did not work. You need to create the Action and use the Keys.chord. THANK YOU.
    – nettie
    Jul 22, 2021 at 14:31
0

Try to use javascript click which will click on the element given it is present unlike the webdriver selenium click which needs the element to be displayed first.

driver.executeScript("arguments[0].click();", element)
1
  • This only works with buttons.
    – DinoMyte
    Dec 22, 2021 at 21:01
0

https://github.com/SDETRahulJain/ReactDriverCSharp.git Help to locate control in react based application with Selenium & C#

3
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Aug 3, 2022 at 6:44
  • Please edit your answer to explain how the github repository you linked can help the OP
    – Kate Paulk
    Aug 3, 2022 at 12:31
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. Aug 4, 2022 at 7:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.