Selenium How to Access Two Controls of Same CSS Class

Selenium how to access two controls of same css class

You can access first label via:

css=div[class='control-group'] label[class='control-label']:contains('Email')

You can access second lavel via:

css=div[class='control-group'] label[class='control-label']:contains('Password')

Use these with command assertElementPresent, "contains" in element locator allows you to verify text in it.

Also you can use xpath:

//div[@class='control-group']//label[@class='control-label'][text()='Email']
//div[@class='control-group']//label[@class='control-label'][text()='Password']

Usually maxlength property is set as attribute of the input, but i can't see it in your html code.. But you can try:

storeAttribute (Selenium IDE's command) and as target you can use xpath:

/div[@class='control-group']//label[@class='control-label'][text()='Email']/@maxlength
save it to some var (eg set to the value field smthg like attLength) and then echo this var like: Selenium IDE's command echo and as put to the target field ${attLength}

How to access the second element that has the same class name in selenium using java

You can use xpath indexing option.

By.xpath("(//input[@name='Button'])[2]")

How to select button inside of multiple classes with selenium python?

Find elements instead by CSS selector:

driver.find_element(By.CSS_SELECTOR, ".card-summer_1 .button-class")

How can I select multiple button with same id in python selenium

Though both the buttons are having the same value i.e. 1 for the id attribute but they are located at different location within the Viewport and you have you select i.e. invoke click() on them individually.

The desired element is a Ember.js enabled element, so ideally, to click on the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • XPath to click the first element:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@id='bedroomNum']//div[@id='1']/span[text()='1']"))).click()
  • CSS_SELECTOR to click the first element:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div#bedroomNum div#1 > span"))).click()
  • XPath to click the second element:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@id='bathroomNum']//div[@id='1']/span[text()='1']"))).click()
  • CSS_SELECTOR to click the second element:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div#bathroomNum div#1 > span"))).click()
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC


Related Topics



Leave a reply



Submit