问题
I'm new to Selenium and VBA. What i want to do is automate selection of a certain TEXT in a CSS. Selenium brings me this:
css=.x-grid3-row:nth-child(42) .x-grid3-col:nth-child(4) > .x-grid3-cell-inner
Everyting would be fine, except the TEXT I want to select sometimes move to different grid3-row:nth-child
What I want to achieve is to find in which x-grid3-row:nth-child
the desired TEXT is so I could click it with a VBA bot.
Thank you for your help.
回答1:
You won't be able to construct a css-selectors passing the desired text.
You can find a relevant detailed discussion in selenium.common.exceptions.InvalidSelectorException with “span:contains('string')”
As an alternative you can use a xpath based Locator Strategy as follows:
driver.FindElementByXPath("//*[@class='x-grid3-cell-inner' and text()='certain_text']")
来源:https://stackoverflow.com/questions/62532038/vba-to-find-if-an-element-contains-certain-texts