Я работаю над Selenium и пытаюсь получить доступ к тексту из узла, но я не уверен, как получить и утверждать текст с одобренным ключевым словом. < /p>
Это узел - < /p>
User Name approved "Page_For_Submission"
4 hours ago
< /code>
Первоначально я попробовал этот XPath, но он не дает результата - < /p>
(//span[contains(@class,'title')]/following-sibling::text()[contains(text(),'approved')])[1]
< /code>
означает, что это не простой текстовый узел. < /p>
Позже я использовал следующие xpaths и способен найти положение элемента < /p>
(//html/body/div[7]/div[3]/div[2]/div/div/div/div/ul/li[2]/a/div/div/div/div/span/text())[2]
< /code>
//span[contains(@class,'title')]/following-sibling::text()
< /code>
(//span[contains(@class,'title')]/following-sibling::text()[contains(.,'approved')])[1]
< /code>
But by using these XPaths in selenium
System.out.println(driver.findElement(By.xpath(prop.getProperty("txt_approvedNotification"))).getText());
< /code>
Getting following error while executing
org.openqa.selenium.InvalidSelectorException: invalid selector: The result of the xpath expression "(XPath of Element)[2]" is: [object Text]. It should be an element.
(Session info: chrome=77.0.3865.90)
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:26:55.152Z'
System info: host: '*****', ip: '*****', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_191'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 77.0.3865.90,
< /code>
Just want to know if its XPath issue or seleniumdriver limitation.
Подробнее здесь: https://stackoverflow.com/questions/581 ... -via-xpath