'Can write any other code to move the question in MS-Form using Python selenium, if element class have changed?
I am trying to use Python Selenium to move the question in Microsoft Form by clicking "↓", move-question-down icon (Fig 1).
The HTML structure is in Fig 2 (the code of HTML code in Google Chrome's inspect element is below.)
<div>
<button aria-disabled="false" aria-label="Move question down" class="css-408">
<span class="-ge-143">
<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" class="-gl-144"><path d="M19.7905 13.26.....20.6862L19.7905 13.2673Z"></path>
</svg>
</span>
</button>
</div>
I have tried to run this code:
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
driver = webdriver.Chrome()
driver.get('https://forms.office.com/Pages/DesignPageV2.....')
driver.find_element_by_xpath('//*[@aria-label="Move question down"]/span[1]/*[name()="svg"][@class="-gl-144"]').click()
It works fine. But I wonder if it can be written more concisely?
And just noticed that the class (class="-gl-144") is not constant. It will change the next day. !!! Why ???
Is there a better way to write?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|