Read a dynamic value using Selenium

0 votes

I was getting the element in a HTML i.e value "1841". I can find the element for the next element by:

e = b.find_element_by_xpath("//*[contains(text(), 'value_to_alert')]")

 How to get the element before this element... I don’t want to use the class name because there are a bunch of "KpiValue"s. Is there a way to do that?

Aug 2, 2018 in Selenium by Martin
• 4,330 points
1,489 views

1 answer to this question.

0 votes

You can use the following line of code:

text = b.find_element_by_xpath("//div[contains(.,'value_to_alert')]//preceding::div[1]").text

answered Aug 2, 2018 by Samarpit
• 5,890 points

Related Questions In Selenium

0 votes
2 answers

Is it possible to manually set the attribute value of a Web Element using Selenium?

WebDriver driver; JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("document.getElementById('id123').setAttribute('attr', ...READ MORE

answered Sep 3 in Selenium by Sri
• 2,970 points
14,992 views
0 votes
1 answer

Read PDF content on a browser using Selenium webdriver?

Hey Parvati, you can use Apache PDFBox JAR ...READ MORE

answered Jul 5, 2019 in Selenium by Abha
• 27,930 points
5,398 views
0 votes
1 answer

How can I read a CSV file in Selenium using Webdriver?

Hey Trisha, you can read a CSV ...READ MORE

answered Jul 17, 2019 in Selenium by Abha
• 27,930 points
4,807 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,510 points
3,507 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31 in Selenium by Sri
• 2,970 points
4,509 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,890 points
2,584 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 2 in Selenium by Sri
• 2,970 points
2,839 views
0 votes
1 answer

Select a drop down value of angular js application using selenium using text

To select drop down use following, driver.findElements(By.className("Your dropdown ...READ MORE

answered Jun 18, 2018 in Selenium by Samarpit
• 5,890 points
4,680 views
0 votes
1 answer

How to login a forum using Selenium with Python

You should try to directly log in ...READ MORE

answered Apr 27, 2018 in Selenium by Samarpit
• 5,890 points
769 views