satish reddy
satish reddy

Reputation: 1

How to Find elements using multiple attributes

I tried to find element from html using the id which is having numbers at the end but when I running the scripts the element is getting changed and can't find the element while running.Please suggest me the best way to find dynamic elements in web application using selenium

Upvotes: 0

Views: 1864

Answers (3)

Sumit Kapoor
Sumit Kapoor

Reputation: 1119

If you are doing it in python you can use time.sleep() function and pass any numeric value like time.sleep(10).It is done for your page to fully load then you can extract the value of those html elements using selenium's attributes like-:

driver.find_element_by_id('')
driver.find_element_by_css_selector('')
driver.find_element_by_class_name('')
driver.find_element_by_xpath('')
driver.find_element_by_link_text('')
driver.find_element_by_partial_link_text('').

Upvotes: 0

Andersson
Andersson

Reputation: 52665

Same could be done with xpath. Python sample will looks like follow:

driver.find_element_by_xpath('//*[contains(@id, "your_static_part")]')

Upvotes: 1

alecxe
alecxe

Reputation: 473773

the id which is having numbers at the end

Assuming the id has something static in the beginning, you can check that id starts with something you know it would start with. Sample in Java:

driver.findElements(By.cssSelector("[id^=something_static]"));

Here the [id^=something_static] is a CSS selector and ^= is a starts-with notation.

Upvotes: 2

Related Questions