Issue
I try to access two dropdowns using selenium and python. The first problem is that, the class for second button is not too stable meaning, after selecting an option, the class name is changing. __________ SECOND BUTTON _____________
awsui-select-trigger-placeholder
Before: After selecting first option:
____________ FIRST BUTTON _____________
Second issue is that the first button has same class
awsui-select-trigger-label
After selecting the option:
Is there a way I could access the class more dynamically?
I'm using this code for the second button:
att3 = WebDriverWait(driver, 5).until(
ec.element_to_be_clickable(
(By.CLASS_NAME,
'awsui-select-trigger-placeholder')))
Thank you so much.
Solution
Instead of locating by entire class name
att3 = WebDriverWait(driver, 5).until(ec.element_to_be_clickable((By.CLASS_NAME, 'awsui-select-trigger-placeholder')))
You can use this XPath locator
att3 = WebDriverWait(driver, 20).until(ec.element_to_be_clickable((By.XPATH, '//*[contains(@class,"awsui-select-trigger-")]')))
Or css selector like this:
att3 = WebDriverWait(driver, 20).until(ec.element_to_be_clickable((By.CSS_SELECTOR, '[class*="awsui-select-trigger-"]')))
I can't validate uniqueness of the locators above since you didn't share a link to the page you are working on.
Also I would advice you to use visibility_of_element_located
instead of element_to_be_clickable
if it can be applicable on that element.
UPD
Since class name attribute is changing for both elements you can construct the locators based on their parent elements.
So the first element can be clicked as following:
WebDriverWait(driver, 20).until(ec.element_to_be_clickable((By.XPATH, '//span[@id="awsui-select-0-textbox"]//span[contains(@class,"awsui-select-trigger-")]'))).click()
Or even
WebDriverWait(driver, 20).until(ec.element_to_be_clickable((By.XPATH, '//span[@id="awsui-select-0-textbox"]/span'))).click()
While the second element can be clicked by:
WebDriverWait(driver, 20).until(ec.element_to_be_clickable((By.XPATH, '//span[@id="awsui-select-21-textbox"]//span[contains(@class,"awsui-select-trigger-")]'))).click()
Or respectively
WebDriverWait(driver, 20).until(ec.element_to_be_clickable((By.XPATH, '//span[@id="awsui-select-21-textbox"]/span'))).click()
Answered By - Prophet
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.