Sorry guys, I asked the same question before but I can't apply in my real task. (please see previous quest tion here)
I got 2 trouble: 1/ project based on SeleniumLibrary and I don't know how to call find_element_by_xpath or something else in common (import webdriver)
2/ with these code below, the SeleniumLibrary tell me that is not valid XPATH expression.
driver = SeleniumLibrary
driver.open_browser("abc.com")
driver.find_element("//div[@id='react-select-2--value']").click()
driver.find_element("//[test()='Core']) --> Error here "str... is invalid XPATH Expression"
3/ in previous question, I solved the problem (as people's answers)
1.
driver.get("https://react-select.com/home")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.basic-single > div.select__control > div.select__value-container"))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[contains(@class, 'select__menu')]/div[contains(@class, 'select__menu-list')]//div[contains(@class, 'select__option') and text()='Green']"))).click()
or:
driver.get("https://react-select.com/home")
driver.maximize_window()
driver.find_element_by_xpath("//div[@class='select__value-container select__value-container--has-value css-1hwfws3']").click()
driver.find_element_by_xpath("//*[text()='Green']").click()
@ add span tag
<span class="Select-value-label resourceValue" style="margin-left: 5px;" xpath="1">Core</span>
driver.find_element("//[test()='Core'])
you have not provided the tag
driver.find_element("//*[test()='Core']")
you can privide * indicating any tag or specify which tag input,div etc
Also see the elements are in iframe or not , if its inside iframe then you have to switch to it before you could interact with it.
iframe = driver.find_element_by_xpath("//iframe")
driver.switch_to_frame(iframe)
driver.find_element("//div[@id='react-select-2--value']").click()
driver.find_element("//*[test()='Core']")
Abd if you have to interact with element outside iframe then, then you have to switch out from iframe first:
driver.switch_to_default_content()
//rest of code