๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
  • Tried. Failed. Logged.
๐Ÿ‘จ๐Ÿผ‍๐Ÿ’ป๊ฐœ๋ฐœ/์…€๋ ˆ๋‹ˆ์›€

์…€๋ ˆ๋‹ˆ์›€ - xpath, ํ…์ŠคํŠธ๊ฐ€ ํฌํ•จ๋œ ์š”์†Œ ์„ ํƒ(contains text)

by Janger 2023. 5. 7.
728x90

 

์›ํ•˜๋Š” ๋ฌธ์ž์—ด์ธ ์š”์†Œ ์ฐพ๊ธฐ

 

ex) ์š”์†Œ์˜ ๋‚ด์šฉ์ด foo์ธ ๊ฒƒ์„ ์ฐพ๊ธฐ

 

//myparent/mychild[text() = 'foo']

 

 

 

 

์›ํ•˜๋Š” ๋ฌธ์ž์—ด์ด ํฌํ•จํ•œ(contains) ์š”์†Œ ์ฐพ๊ธฐ

 

ex) ABC๋ผ๋Š” ๋‚ด์šฉ์„ ํฌํ•จํ•œ ์žˆ๋Š” ์š”์†Œ ์ฐพ๊ธฐ

 

//*[contains(text(),'ABC')]

 

ํŒŒ์ด์ฌ ์‚ฌ์šฉ ์˜ˆ์‹œ
driver.find_element_by_xpath('//span[contains(text(),"ABC")]')

 

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ(๋ธŒ๋ผ์šฐ์ € ๊ฐœ๋ฐœ์ž ๋„๊ตฌ) ์‚ฌ์šฉ ์˜ˆ์‹œ
$x("//*[contains(text(),'12:00')]")

 

๊ทธ ๋ฌธ์ž์ธ ๊ฒƒ์„ ์ฐพ๊ธฐ
$x('//*[text()="๋„ค์ด๋ฒ„๋กœ ์ด์šฉํ•˜๊ธฐ"]')

 

 

์†์„ฑ(class๋‚˜ id) ๊ฐ’์ด ํŠน์ • ๋ฌธ์ž๋กœ ์‹œ์ž‘ํ•˜๋Š” ์š”์†Œ ์ฐพ๊ธฐ
$x("//div[starts-with(@class, 'PP-')]")

 

 

์ถœ์ฒ˜: 

 

https://stackoverflow.com/questions/1998681/xpath-selection-by-innertext

 

XPath selection by innertext

I'm trying to extract an element with a particular innertext from a parsed XML document. I know that I can select an element that has a child with a particular innertext using //myparent[mychild='...

stackoverflow.com

 

https://stackoverflow.com/questions/3655549/xpath-containstext-some-string-doesnt-work-when-used-with-node-with-more

 

XPath contains(text(),'some string') doesn't work when used with node with more than one Text subnode

I have a small problem with XPath contains with dom4j ... Let's say my XML is <Home> <Addr> <Street>ABC</Street> <Number>5</Number> <

stackoverflow.com

 

https://stackoverflow.com/questions/40853883/python-selenium-find-element-whose-class-name-starts-with-something

 

Python Selenium - Find element whose class name starts with something

How can I retreive an element whose class name starts with, let's say: "PP-". I tried this without success: driver.find_element_by_css_selector("div[class^='PP-']")

stackoverflow.com

 

728x90