0

I'm trying to check if a word is or is not on a webpage by using Selenium on Python. The problem is the word is dynamic: it will only appear after I do some action (in my case, selecting an option on a dropdown list).

I've tried to use

"text" is in driver.page_source"

But it doesn't work: it will not detect my dynamic text (even though it detects other static texts).

I have no idea why it doesn't work.

Rob
  • 37
  • 1
  • 6
  • Please check if you get the page source *after* doing actions which will make the text appear: ` do_some_actions() "text" in driver.page_source ` . If you are sure you do everything right, please, provide an example (or link) –  Feb 22 '20 at 15:29
  • Usually the text appears or disappears is controlled by a webpage element. Try using implicit (`driver.implicitly_wait`) or explicit (`WebDriverWait`) wait to poll the element. See [here](https://selenium-python.readthedocs.io/waits.html) – FearlessSniper Feb 22 '20 at 15:35
  • @NChechulin @FearlessSniper Thank you for your help. That's actually what my code looks like : `driver.get('http//exemple.com')` `driver.implictly_wait(10)` `# code to make the text appear` `driver.implictly_wait(10)` `if "text" is in driver.page_source:` `print('Exist')` `else:` `print('Not exist')` – Rob Feb 22 '20 at 15:52
  • what is the tag that include text? – CC7052 Feb 22 '20 at 16:02
  • @Rob Can you try mimicking user behavior like selecting the dropdown menu, then try to retrieve the text? Sometimes on-page javascripts removes the element from page instead of setting it to invisible. – FearlessSniper Feb 22 '20 at 16:26
  • AC:1000000012 The text is the AC:10000XXX – Rob Feb 22 '20 at 16:27
  • When I do it myself (dropping down the menu to select an option and selecting an option), I see the text appearing. What do you mean trying to retrieve the text? – Rob Feb 22 '20 at 16:29

0 Answers0