0

pic1

pic2

I need to find element "16" , my project using driver = SeleniumLibrary

driver.open_browswer("..."_
driver.find_element ("//div[@id='react-select-4--value']").click()
driver.scroll_element_into_view("//span[contains(text(),'16']")
driver.find_element("//span[contains(text(),'16']").click()

I could click on the react-dropdown list but I can't use scroll_element_into_view to find that element then click()

Scorpisces
  • 69
  • 1
  • 9

2 Answers2

1

If there is input element you can directly send '16' like this

driver.find_element_by_xpath('xpath_of_element').send_keys(16)

and If there is Option element then you can select using following method

from selenium.webdriver.support.ui import Select

element = Select(driver.find_element_by_xpath("//div[@id='react-select-4--value']"))
element.select_by_value("16")
Haseeb Ahmed
  • 265
  • 3
  • 10
  • when I send_keys(16) It showed line 16 but It looks like a suggestion, I need "enter" or click on the line to choose. But after send_keys(16) and send_keys(Keys.RETURN) it can't find the that xpath, the input xpath – Scorpisces Jan 15 '21 at 07:09
  • It seems not having "option" to select and with SeleniumLibrary I don't know how to call Select @@ – Scorpisces Jan 15 '21 at 07:36
0
option = driver.find_element("//span[contains(text(),'16')]")
driver.execute_javascript("arguments[0].scrollIntoView();", option)

Could you try this,

PDHide
  • 18,113
  • 2
  • 31
  • 46
  • option = test.driver.find_element("//span[contains(text(),'16']") ---> SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//span[contains(text(),'16']' is not a valid XPath expression. – Scorpisces Jan 15 '21 at 08:03
  • 1
    @Scorpisces i just copy pasted locator from your question , it was missing a bracket updated now – PDHide Jan 15 '21 at 08:04
  • It show a list 0, 1,2,3,... and resonse that the xpath can't found. I think I can use: `driver.find_element('xpath').send_keys("16")` -> and try to `send_key(Keys.RETURN)` but It needs a locator to send_keys `driver.find_element('xpath').send_keys(Keys.RETURN)"` or `r"\ue007"` not work – Scorpisces Jan 15 '21 at 08:28
  • `Exception: Error 'SeleniumLibrary' object has no attribute 'execute_script'` @PDHide – Scorpisces Jan 15 '21 at 08:37
  • 1
    use execute_javascript – PDHide Jan 15 '21 at 08:39
  • It only expand a dropdown 0 1 2 3 4 5 and resonsed: `Exception: Error Element with locator '//span[contains(text(),'16')]' not found.` – Scorpisces Jan 15 '21 at 08:49
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/227374/discussion-between-scorpisces-and-pdhide). – Scorpisces Jan 15 '21 at 09:11